<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE ScopedTypeVariables, CPP, BangPatterns, RankNTypes #-}</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ == 700
</span><span class="hs-comment">-- This is needed as a workaround for an old bug in GHC 7.0.1 (Trac #4498)</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE MonoPatBinds #-}</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">#if __GLASGOW_HASKELL__ &gt;= 703
</span><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span class="hs-cpp">
#endif
</span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- | Copyright : (c) 2010 - 2011 Simon Meier</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- License     : BSD3-style (see LICENSE)</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Maintainer  : Simon Meier &lt;iridcode@gmail.com&gt;</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Stability   : unstable, private</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Portability : GHC</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- *Warning:* this module is internal. If you find that you need it then please</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- contact the maintainers and explain what you are trying to do and discuss</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- what you would need in the public API. It is important that you do this as</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- the module may not be exposed at all in future releases.</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- Core types and functions for the 'Builder' monoid and its generalization,</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- the 'Put' monad.</span><span>
</span><span id="line-24"></span><span class="hs-comment">--</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- The design of the 'Builder' monoid is optimized such that</span><span>
</span><span id="line-26"></span><span class="hs-comment">--</span><span>
</span><span id="line-27"></span><span class="hs-comment">--   1. buffers of arbitrary size can be filled as efficiently as possible and</span><span>
</span><span id="line-28"></span><span class="hs-comment">--</span><span>
</span><span id="line-29"></span><span class="hs-comment">--   2. sequencing of 'Builder's is as cheap as possible.</span><span>
</span><span id="line-30"></span><span class="hs-comment">--</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- We achieve (1) by completely handing over control over writing to the buffer</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- to the 'BuildStep' implementing the 'Builder'. This 'BuildStep' is just told</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- the start and the end of the buffer (represented as a 'BufferRange'). Then,</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- the 'BuildStep' can write to as big a prefix of this 'BufferRange' in any</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- way it desires. If the 'BuildStep' is done, the 'BufferRange' is full, or a</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- long sequence of bytes should be inserted directly, then the 'BuildStep'</span><span>
</span><span id="line-37"></span><span class="hs-comment">-- signals this to its caller using a 'BuildSignal'.</span><span>
</span><span id="line-38"></span><span class="hs-comment">--</span><span>
</span><span id="line-39"></span><span class="hs-comment">-- We achieve (2) by requiring that every 'Builder' is implemented by a</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- 'BuildStep' that takes a continuation 'BuildStep', which it calls with the</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- updated 'BufferRange' after it is done. Therefore, only two pointers have</span><span>
</span><span id="line-42"></span><span class="hs-comment">-- to be passed in a function call to implement concatenation of 'Builder's.</span><span>
</span><span id="line-43"></span><span class="hs-comment">-- Moreover, many 'Builder's are completely inlined, which enables the compiler</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- to sequence them without a function call and with no boxing at all.</span><span>
</span><span id="line-45"></span><span class="hs-comment">--</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- This design gives the implementation of a 'Builder' full access to the 'IO'</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- monad. Therefore, utmost care has to be taken to not overwrite anything</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- outside the given 'BufferRange's. Moreover, further care has to be taken to</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- ensure that 'Builder's and 'Put's are referentially transparent. See the</span><span>
</span><span id="line-50"></span><span class="hs-comment">-- comments of the 'builder' and 'put' functions for further information.</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- Note that there are /no safety belts/ at all, when implementing a 'Builder'</span><span>
</span><span id="line-52"></span><span class="hs-comment">-- using an 'IO' action: you are writing code that might enable the next</span><span>
</span><span id="line-53"></span><span class="hs-comment">-- buffer-overflow attack on a Haskell server!</span><span>
</span><span id="line-54"></span><span class="hs-comment">--</span><span>
</span><span id="line-55"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.ByteString.Builder.Internal</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-56"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Buffer management</span></span><span>
</span><span id="line-57"></span><span>    </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier">Buffer</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier">BufferRange</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-59"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier">newBuffer</span></a></span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#bufferSize"><span class="hs-identifier">bufferSize</span></a></span><span>
</span><span id="line-61"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringFromBuffer"><span class="hs-identifier">byteStringFromBuffer</span></a></span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier">ChunkIOStream</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#buildStepToCIOS"><span class="hs-identifier">buildStepToCIOS</span></a></span><span>
</span><span id="line-65"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ciosUnitToLazyByteString"><span class="hs-identifier">ciosUnitToLazyByteString</span></a></span><span>
</span><span id="line-66"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ciosToLazyByteString"><span class="hs-identifier">ciosToLazyByteString</span></a></span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Build signals and steps</span></span><span>
</span><span id="line-69"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildSignal"><span class="hs-identifier">BuildSignal</span></a></span><span>
</span><span id="line-70"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier">BuildStep</span></a></span><span>
</span><span id="line-71"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#finalBuildStep"><span class="hs-identifier">finalBuildStep</span></a></span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#done"><span class="hs-identifier">done</span></a></span><span>
</span><span id="line-74"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-identifier">bufferFull</span></a></span><span>
</span><span id="line-75"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-identifier">insertChunk</span></a></span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#fillWithBuildStep"><span class="hs-identifier">fillWithBuildStep</span></a></span><span>
</span><span id="line-78"></span><span>
</span><span id="line-79"></span><span>  </span><span class="annot"><span class="hs-comment">-- * The Builder monoid</span></span><span>
</span><span id="line-80"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier">Builder</span></a></span><span>
</span><span id="line-81"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier">builder</span></a></span><span>
</span><span id="line-82"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runBuilder"><span class="hs-identifier">runBuilder</span></a></span><span>
</span><span id="line-83"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runBuilderWith"><span class="hs-identifier">runBuilderWith</span></a></span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Primitive combinators</span></span><span>
</span><span id="line-86"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#empty"><span class="hs-identifier">empty</span></a></span><span>
</span><span id="line-87"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-identifier">append</span></a></span><span>
</span><span id="line-88"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#flush"><span class="hs-identifier">flush</span></a></span><span>
</span><span id="line-89"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ensureFree"><span class="hs-identifier">ensureFree</span></a></span><span>
</span><span id="line-90"></span><span>  </span><span class="hs-comment">-- , sizedChunksInsert</span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringCopy"><span class="hs-identifier">byteStringCopy</span></a></span><span>
</span><span id="line-93"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringInsert"><span class="hs-identifier">byteStringInsert</span></a></span><span>
</span><span id="line-94"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringThreshold"><span class="hs-identifier">byteStringThreshold</span></a></span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringCopy"><span class="hs-identifier">lazyByteStringCopy</span></a></span><span>
</span><span id="line-97"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringInsert"><span class="hs-identifier">lazyByteStringInsert</span></a></span><span>
</span><span id="line-98"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringThreshold"><span class="hs-identifier">lazyByteStringThreshold</span></a></span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#shortByteString"><span class="hs-identifier">shortByteString</span></a></span><span>
</span><span id="line-101"></span><span>
</span><span id="line-102"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#maximalCopySize"><span class="hs-identifier">maximalCopySize</span></a></span><span>
</span><span id="line-103"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteString"><span class="hs-identifier">byteString</span></a></span><span>
</span><span id="line-104"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteString"><span class="hs-identifier">lazyByteString</span></a></span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Execution</span></span><span>
</span><span id="line-107"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#toLazyByteStringWith"><span class="hs-identifier">toLazyByteStringWith</span></a></span><span>
</span><span id="line-108"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier">AllocationStrategy</span></a></span><span>
</span><span id="line-109"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#safeStrategy"><span class="hs-identifier">safeStrategy</span></a></span><span>
</span><span id="line-110"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#untrimmedStrategy"><span class="hs-identifier">untrimmedStrategy</span></a></span><span>
</span><span id="line-111"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#customStrategy"><span class="hs-identifier">customStrategy</span></a></span><span>
</span><span id="line-112"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#smallChunkSize"><span class="hs-identifier">L.smallChunkSize</span></a></span><span>
</span><span id="line-113"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#defaultChunkSize"><span class="hs-identifier">L.defaultChunkSize</span></a></span><span>
</span><span id="line-114"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#chunkOverhead"><span class="hs-identifier">L.chunkOverhead</span></a></span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span>  </span><span class="annot"><span class="hs-comment">-- * The Put monad</span></span><span>
</span><span id="line-117"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier">Put</span></a></span><span>
</span><span id="line-118"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#put"><span class="hs-identifier">put</span></a></span><span>
</span><span id="line-119"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runPut"><span class="hs-identifier">runPut</span></a></span><span>
</span><span id="line-120"></span><span>
</span><span id="line-121"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Execution</span></span><span>
</span><span id="line-122"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putToLazyByteString"><span class="hs-identifier">putToLazyByteString</span></a></span><span>
</span><span id="line-123"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putToLazyByteStringWith"><span class="hs-identifier">putToLazyByteStringWith</span></a></span><span>
</span><span id="line-124"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#hPut"><span class="hs-identifier">hPut</span></a></span><span>
</span><span id="line-125"></span><span>
</span><span id="line-126"></span><span>  </span><span class="annot"><span class="hs-comment">-- ** Conversion to and from Builders</span></span><span>
</span><span id="line-127"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-identifier">putBuilder</span></a></span><span>
</span><span id="line-128"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#fromPut"><span class="hs-identifier">fromPut</span></a></span><span>
</span><span id="line-129"></span><span>
</span><span id="line-130"></span><span>  </span><span class="hs-comment">-- -- ** Lifting IO actions</span><span>
</span><span id="line-131"></span><span>  </span><span class="hs-comment">-- , putLiftIO</span><span>
</span><span id="line-132"></span><span>
</span><span id="line-133"></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-134"></span><span>
</span><span id="line-135"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Control.Arrow.html#"><span class="hs-identifier">Control.Arrow</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Control.Arrow.html#second"><span class="hs-identifier">second</span></a></span><span class="hs-special">)</span><span class="hs-cpp">

#if !(MIN_VERSION_base(4,11,0)) &amp;&amp; MIN_VERSION_base(4,9,0)
</span><span class="hs-keyword">import</span><span>           </span><span class="hs-identifier">Data.Semigroup</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Semigroup</span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-operator">&lt;&gt;</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">#if !(MIN_VERSION_base(4,8,0))
</span><span class="hs-keyword">import</span><span>           </span><span class="hs-identifier">Data.Monoid</span><span>
</span><span id="line-142"></span><span class="hs-keyword">import</span><span>           </span><span class="hs-identifier">Control.Applicative</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Applicative</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span class="hs-special">(</span><span class="hs-operator">&lt;$&gt;</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-145"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="Data.ByteString.html"><span class="hs-identifier">Data.ByteString</span></a></span><span>               </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">S</span></span><span>
</span><span id="line-146"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html"><span class="hs-identifier">Data.ByteString.Internal</span></a></span><span>      </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">S</span></span><span>
</span><span id="line-147"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html"><span class="hs-identifier">Data.ByteString.Lazy.Internal</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">L</span></span><span>
</span><span id="line-148"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="Data.ByteString.Short.Internal.html"><span class="hs-identifier">Data.ByteString.Short.Internal</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Sh</span></span><span class="hs-cpp">

#if __GLASGOW_HASKELL__ &gt;= 611
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Buffer.html#"><span class="hs-identifier">GHC.IO.Buffer</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.Buffer.html#Buffer"><span class="hs-identifier">Buffer</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Buffer.html#newByteBuffer"><span class="hs-identifier">newByteBuffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-152"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Internals.html#"><span class="hs-identifier">GHC.IO.Handle.Internals</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier">wantWritableHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier">flushWriteBuffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-153"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#"><span class="hs-identifier">GHC.IO.Handle.Types</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier">Handle__</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#haByteBuffer"><span class="hs-identifier">haByteBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#haBufferMode"><span class="hs-identifier">haBufferMode</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-154"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/System.IO.html#"><span class="hs-identifier">System.IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.Handle.html#hFlush"><span class="hs-identifier">hFlush</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#BufferMode"><span class="hs-identifier">BufferMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-155"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Data.IORef.html#"><span class="hs-identifier">Data.IORef</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">Data.ByteString.Lazy</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">L</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/System.IO.html#"><span class="hs-identifier">System.IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier">Handle</span></a></span><span class="hs-special">)</span><span class="hs-cpp">

#if MIN_VERSION_base(4,4,0)
</span><span class="hs-cpp">#if MIN_VERSION_base(4,7,0)
</span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Foreign.html#"><span class="hs-identifier">Foreign</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span>           </span><span class="hs-identifier">Foreign</span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">unsafeForeignPtrToPtr</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Foreign.ForeignPtr.Unsafe.html#"><span class="hs-identifier">Foreign.ForeignPtr.Unsafe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier">unsafeForeignPtrToPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-168"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/System.IO.Unsafe.html#"><span class="hs-identifier">System.IO.Unsafe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier">unsafeDupablePerformIO</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span>           </span><span class="hs-identifier">Foreign</span><span>
</span><span id="line-171"></span><span class="hs-keyword">import</span><span>           </span><span class="hs-identifier">GHC.IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">unsafeDupablePerformIO</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-174"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-175"></span><span class="hs-comment">-- Buffers</span><span>
</span><span id="line-176"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-177"></span><span class="hs-comment">-- | A range of bytes in a buffer represented by the pointer to the first byte</span><span>
</span><span id="line-178"></span><span class="hs-comment">-- of the range and the pointer to the first byte /after/ the range.</span><span>
</span><span id="line-179"></span><span class="hs-keyword">data</span><span> </span><span id="BufferRange"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="BufferRange"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- First byte of range</span><span>
</span><span id="line-180"></span><span>                               </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- First byte /after/ range</span><span>
</span><span id="line-181"></span><span>
</span><span id="line-182"></span><span class="hs-comment">-- | A 'Buffer' together with the 'BufferRange' of free bytes. The filled</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- space starts at offset 0 and ends at the first free byte.</span><span>
</span><span id="line-184"></span><span class="hs-keyword">data</span><span> </span><span id="Buffer"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-var">Buffer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Buffer"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-var">Buffer</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#ForeignPtr"><span class="hs-identifier hs-type">ForeignPtr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-185"></span><span>                     </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span>
</span><span id="line-186"></span><span>
</span><span id="line-187"></span><span>
</span><span id="line-188"></span><span class="hs-comment">-- | Combined size of the filled and free space in the buffer.</span><span>
</span><span id="line-189"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#bufferSize"><span class="hs-pragma hs-type">bufferSize</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-190"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#bufferSize"><span class="hs-identifier hs-type">bufferSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-191"></span><span id="bufferSize"><span class="annot"><span class="annottext">bufferSize :: Buffer -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#bufferSize"><span class="hs-identifier hs-var hs-var">bufferSize</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span id="local-6989586621679077887"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077887"><span class="hs-identifier hs-var">fpbuf</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679077886"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077886"><span class="hs-identifier hs-var">ope</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-192"></span><span>    </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077886"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Ptr Word8
forall a. ForeignPtr a -&gt; Ptr a
</span><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier hs-var">unsafeForeignPtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077887"><span class="hs-identifier hs-var">fpbuf</span></a></span><span>
</span><span id="line-193"></span><span>
</span><span id="line-194"></span><span class="hs-comment">-- | Allocate a new buffer of the given size.</span><span>
</span><span id="line-195"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-pragma hs-type">newBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-196"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier hs-type">newBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span>
</span><span id="line-197"></span><span id="newBuffer"><span class="annot"><span class="annottext">newBuffer :: Int -&gt; IO Buffer
</span><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier hs-var hs-var">newBuffer</span></a></span></span><span> </span><span id="local-6989586621679077884"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077884"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-198"></span><span>    </span><span id="local-6989586621679077883"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077883"><span class="hs-identifier hs-var">fpbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (ForeignPtr Word8)
forall a. Int -&gt; IO (ForeignPtr a)
</span><a href="Data.ByteString.Internal.html#mallocByteString"><span class="hs-identifier hs-var">S.mallocByteString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077884"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-199"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679077881"><span class="annot"><span class="annottext">pbuf :: Ptr Word8
</span><a href="#local-6989586621679077881"><span class="hs-identifier hs-var hs-var">pbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Ptr Word8
forall a. ForeignPtr a -&gt; Ptr a
</span><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier hs-var">unsafeForeignPtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077883"><span class="hs-identifier hs-var">fpbuf</span></a></span><span>
</span><span id="line-200"></span><span>    </span><span class="annot"><span class="annottext">Buffer -&gt; IO Buffer
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Buffer -&gt; IO Buffer) -&gt; Buffer -&gt; IO Buffer
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; BufferRange -&gt; Buffer
</span><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-var">Buffer</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077883"><span class="hs-identifier hs-var">fpbuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077881"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077881"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077884"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-201"></span><span>
</span><span id="line-202"></span><span class="hs-comment">-- | Convert the filled part of a 'Buffer' to a strict 'S.ByteString'.</span><span>
</span><span id="line-203"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringFromBuffer"><span class="hs-pragma hs-type">byteStringFromBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-204"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringFromBuffer"><span class="hs-identifier hs-type">byteStringFromBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span>
</span><span id="line-205"></span><span id="byteStringFromBuffer"><span class="annot"><span class="annottext">byteStringFromBuffer :: Buffer -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#byteStringFromBuffer"><span class="hs-identifier hs-var hs-var">byteStringFromBuffer</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span id="local-6989586621679077878"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077878"><span class="hs-identifier hs-var">fpbuf</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077877"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077877"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-206"></span><span>    </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">S.PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077878"><span class="hs-identifier hs-var">fpbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077877"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Ptr Word8
forall a. ForeignPtr a -&gt; Ptr a
</span><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier hs-var">unsafeForeignPtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077878"><span class="hs-identifier hs-var">fpbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-207"></span><span>
</span><span id="line-208"></span><span class="hs-comment">-- | Prepend the filled part of a 'Buffer' to a lazy 'L.ByteString'</span><span>
</span><span id="line-209"></span><span class="hs-comment">-- trimming it if necessary.</span><span>
</span><span id="line-210"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#trimmedChunkFromBuffer"><span class="hs-pragma hs-type">trimmedChunkFromBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-211"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#trimmedChunkFromBuffer"><span class="hs-identifier hs-type">trimmedChunkFromBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span>
</span><span id="line-212"></span><span>                       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span>
</span><span id="line-213"></span><span id="trimmedChunkFromBuffer"><span class="annot"><span class="annottext">trimmedChunkFromBuffer :: AllocationStrategy -&gt; Buffer -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#trimmedChunkFromBuffer"><span class="hs-identifier hs-var hs-var">trimmedChunkFromBuffer</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679077873"><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
</span><a href="#local-6989586621679077873"><span class="hs-identifier hs-var">trim</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679077872"><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077872"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span id="local-6989586621679077871"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077871"><span class="hs-identifier hs-var">k</span></a></span></span><span>
</span><span id="line-214"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; Bool
</span><a href="Data.ByteString.html#null"><span class="hs-identifier hs-var">S.null</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077869"><span class="hs-identifier hs-var">bs</span></a></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077871"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-215"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
</span><a href="#local-6989586621679077873"><span class="hs-identifier hs-var">trim</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteString -&gt; Int
</span><a href="Data.ByteString.html#length"><span class="hs-identifier hs-var">S.length</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077869"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#bufferSize"><span class="hs-identifier hs-var">bufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077872"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Lazy.Internal.html#Chunk"><span class="hs-identifier hs-var">L.Chunk</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteString -&gt; ByteString
</span><a href="Data.ByteString.html#copy"><span class="hs-identifier hs-var">S.copy</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077869"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077871"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-216"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Lazy.Internal.html#Chunk"><span class="hs-identifier hs-var">L.Chunk</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077869"><span class="hs-identifier hs-var">bs</span></a></span><span>          </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077871"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-217"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-218"></span><span>    </span><span id="local-6989586621679077869"><span class="annot"><span class="annottext">bs :: ByteString
</span><a href="#local-6989586621679077869"><span class="hs-identifier hs-var hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#byteStringFromBuffer"><span class="hs-identifier hs-var">byteStringFromBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077872"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-219"></span><span>
</span><span id="line-220"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-221"></span><span class="hs-comment">-- Chunked IO Stream</span><span>
</span><span id="line-222"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-223"></span><span>
</span><span id="line-224"></span><span class="hs-comment">-- | A stream of chunks that are constructed in the 'IO' monad.</span><span>
</span><span id="line-225"></span><span class="hs-comment">--</span><span>
</span><span id="line-226"></span><span class="hs-comment">-- This datatype serves as the common interface for the buffer-by-buffer</span><span>
</span><span id="line-227"></span><span class="hs-comment">-- execution of a 'BuildStep' by 'buildStepToCIOS'. Typical users of this</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- interface are 'ciosToLazyByteString' or iteratee-style libraries like</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- @enumerator@.</span><span>
</span><span id="line-230"></span><span class="hs-keyword">data</span><span> </span><span id="ChunkIOStream"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-var">ChunkIOStream</span></a></span></span><span> </span><span id="local-6989586621679078152"><span class="annot"><a href="#local-6989586621679078152"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-231"></span><span>       </span><span id="Finished"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Finished"><span class="hs-identifier hs-var">Finished</span></a></span></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078152"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-232"></span><span>       </span><span class="hs-comment">-- ^ The partially filled last buffer together with the result.</span><span>
</span><span id="line-233"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span id="Yield1"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Yield1"><span class="hs-identifier hs-var">Yield1</span></a></span></span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-type">ChunkIOStream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078152"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-234"></span><span>       </span><span class="hs-comment">-- ^ Yield a /non-empty/ strict 'S.ByteString'.</span><span>
</span><span id="line-235"></span><span>
</span><span id="line-236"></span><span class="hs-comment">-- | A smart constructor for yielding one chunk that ignores the chunk if</span><span>
</span><span id="line-237"></span><span class="hs-comment">-- it is empty.</span><span>
</span><span id="line-238"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#yield1"><span class="hs-pragma hs-type">yield1</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-239"></span><span id="local-6989586621679078155"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#yield1"><span class="hs-identifier hs-type">yield1</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-type">ChunkIOStream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078155"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-type">ChunkIOStream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078155"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-240"></span><span id="yield1"><span class="annot"><span class="annottext">yield1 :: forall a.
ByteString -&gt; IO (ChunkIOStream a) -&gt; IO (ChunkIOStream a)
</span><a href="Data.ByteString.Builder.Internal.html#yield1"><span class="hs-identifier hs-var hs-var">yield1</span></a></span></span><span> </span><span id="local-6989586621679077861"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077861"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077860"><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077860"><span class="hs-identifier hs-var">cios</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; Bool
</span><a href="Data.ByteString.html#null"><span class="hs-identifier hs-var">S.null</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077861"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077860"><span class="hs-identifier hs-var">cios</span></a></span><span>
</span><span id="line-241"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; IO (ChunkIOStream a))
-&gt; ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
forall a. ByteString -&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
</span><a href="Data.ByteString.Builder.Internal.html#Yield1"><span class="hs-identifier hs-var">Yield1</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077861"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077860"><span class="hs-identifier hs-var">cios</span></a></span><span>
</span><span id="line-242"></span><span>
</span><span id="line-243"></span><span class="hs-comment">-- | Convert a @'ChunkIOStream' ()@ to a lazy 'L.ByteString' using</span><span>
</span><span id="line-244"></span><span class="hs-comment">-- 'unsafeDupablePerformIO'.</span><span>
</span><span id="line-245"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ciosUnitToLazyByteString"><span class="hs-pragma hs-type">ciosUnitToLazyByteString</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-246"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ciosUnitToLazyByteString"><span class="hs-identifier hs-type">ciosUnitToLazyByteString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-247"></span><span>                         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-type">ChunkIOStream</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span>
</span><span id="line-248"></span><span id="ciosUnitToLazyByteString"><span class="annot"><span class="annottext">ciosUnitToLazyByteString :: AllocationStrategy -&gt; ByteString -&gt; ChunkIOStream () -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#ciosUnitToLazyByteString"><span class="hs-identifier hs-var hs-var">ciosUnitToLazyByteString</span></a></span></span><span> </span><span id="local-6989586621679077859"><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077859"><span class="hs-identifier hs-var">strategy</span></a></span></span><span> </span><span id="local-6989586621679077858"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077858"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ChunkIOStream () -&gt; ByteString
forall {a}. ChunkIOStream a -&gt; ByteString
</span><a href="#local-6989586621679077857"><span class="hs-identifier hs-var">go</span></a></span><span>
</span><span id="line-249"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-250"></span><span>    </span><span id="local-6989586621679077857"><span class="annot"><span class="annottext">go :: ChunkIOStream a -&gt; ByteString
</span><a href="#local-6989586621679077857"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Finished"><span class="hs-identifier hs-type">Finished</span></a></span><span> </span><span id="local-6989586621679077854"><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077854"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AllocationStrategy -&gt; Buffer -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#trimmedChunkFromBuffer"><span class="hs-identifier hs-var">trimmedChunkFromBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077859"><span class="hs-identifier hs-var">strategy</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077854"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077858"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-251"></span><span>    </span><span class="annot"><a href="#local-6989586621679077857"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Yield1"><span class="hs-identifier hs-type">Yield1</span></a></span><span> </span><span id="local-6989586621679077853"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077853"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077852"><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077852"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Lazy.Internal.html#Chunk"><span class="hs-identifier hs-var">L.Chunk</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077853"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; ByteString -&gt; ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO ByteString -&gt; ByteString
forall a. IO a -&gt; a
</span><a href="../../base/src/GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier hs-var">unsafeDupablePerformIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; ByteString
</span><a href="#local-6989586621679077857"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; ByteString)
-&gt; IO (ChunkIOStream a) -&gt; IO ByteString
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077852"><span class="hs-identifier hs-var">io</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-252"></span><span>
</span><span id="line-253"></span><span class="hs-comment">-- | Convert a 'ChunkIOStream' to a lazy tuple of the result and the written</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- 'L.ByteString' using 'unsafeDupablePerformIO'.</span><span>
</span><span id="line-255"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ciosToLazyByteString"><span class="hs-pragma hs-type">ciosToLazyByteString</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-256"></span><span id="local-6989586621679078145"><span id="local-6989586621679078146"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ciosToLazyByteString"><span class="hs-identifier hs-type">ciosToLazyByteString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-257"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078146"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078145"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-258"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-type">ChunkIOStream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078146"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-259"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078145"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-260"></span><span id="ciosToLazyByteString"><span class="annot"><span class="annottext">ciosToLazyByteString :: forall a b.
AllocationStrategy
-&gt; (a -&gt; (b, ByteString)) -&gt; ChunkIOStream a -&gt; (b, ByteString)
</span><a href="Data.ByteString.Builder.Internal.html#ciosToLazyByteString"><span class="hs-identifier hs-var hs-var">ciosToLazyByteString</span></a></span></span><span> </span><span id="local-6989586621679077850"><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077850"><span class="hs-identifier hs-var">strategy</span></a></span></span><span> </span><span id="local-6989586621679077849"><span class="annot"><span class="annottext">a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077849"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-261"></span><span>    </span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077848"><span class="hs-identifier hs-var">go</span></a></span><span>
</span><span id="line-262"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-263"></span><span>    </span><span id="local-6989586621679077848"><span class="annot"><span class="annottext">go :: ChunkIOStream a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077848"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Finished"><span class="hs-identifier hs-type">Finished</span></a></span><span> </span><span id="local-6989586621679077843"><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077843"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span id="local-6989586621679077842"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077842"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-264"></span><span>        </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; (b, ByteString) -&gt; (b, ByteString)
forall (a :: * -&gt; * -&gt; *) b c d.
Arrow a =&gt;
a b c -&gt; a (d, b) (d, c)
</span><a href="../../base/src/Control.Arrow.html#second"><span class="hs-identifier hs-var">second</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AllocationStrategy -&gt; Buffer -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#trimmedChunkFromBuffer"><span class="hs-identifier hs-var">trimmedChunkFromBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077850"><span class="hs-identifier hs-var">strategy</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077843"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((b, ByteString) -&gt; (b, ByteString))
-&gt; (b, ByteString) -&gt; (b, ByteString)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077849"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077842"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-265"></span><span>    </span><span class="annot"><a href="#local-6989586621679077848"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Yield1"><span class="hs-identifier hs-type">Yield1</span></a></span><span> </span><span id="local-6989586621679077841"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077841"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077840"><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077840"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; ByteString) -&gt; (b, ByteString) -&gt; (b, ByteString)
forall (a :: * -&gt; * -&gt; *) b c d.
Arrow a =&gt;
a b c -&gt; a (d, b) (d, c)
</span><a href="../../base/src/Control.Arrow.html#second"><span class="hs-identifier hs-var">second</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ByteString -&gt; ByteString -&gt; ByteString
</span><a href="Data.ByteString.Lazy.Internal.html#Chunk"><span class="hs-identifier hs-var">L.Chunk</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077841"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((b, ByteString) -&gt; (b, ByteString))
-&gt; (b, ByteString) -&gt; (b, ByteString)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO (b, ByteString) -&gt; (b, ByteString)
forall a. IO a -&gt; a
</span><a href="../../base/src/GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier hs-var">unsafeDupablePerformIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077848"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; (b, ByteString))
-&gt; IO (ChunkIOStream a) -&gt; IO (b, ByteString)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream a)
</span><a href="#local-6989586621679077840"><span class="hs-identifier hs-var">io</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-266"></span><span>
</span><span id="line-267"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-268"></span><span class="hs-comment">-- Build signals</span><span>
</span><span id="line-269"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-270"></span><span>
</span><span id="line-271"></span><span class="hs-comment">-- | 'BuildStep's may be called *multiple times* and they must not rise an</span><span>
</span><span id="line-272"></span><span class="hs-comment">-- async. exception.</span><span>
</span><span id="line-273"></span><span class="hs-keyword">type</span><span> </span><span id="BuildStep"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-var">BuildStep</span></a></span></span><span> </span><span id="local-6989586621679077839"><span class="annot"><a href="#local-6989586621679077839"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildSignal"><span class="hs-identifier hs-type">BuildSignal</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077839"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-274"></span><span>
</span><span id="line-275"></span><span class="hs-comment">-- | 'BuildSignal's abstract signals to the caller of a 'BuildStep'. There are</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- three signals: 'done', 'bufferFull', or 'insertChunks signals</span><span>
</span><span id="line-277"></span><span class="hs-keyword">data</span><span> </span><span id="BuildSignal"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildSignal"><span class="hs-identifier hs-var">BuildSignal</span></a></span></span><span> </span><span id="local-6989586621679077838"><span class="annot"><a href="#local-6989586621679077838"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-278"></span><span>    </span><span id="Done"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Done"><span class="hs-identifier hs-var">Done</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><a href="#local-6989586621679077838"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-279"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BufferFull"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferFull"><span class="hs-identifier hs-var">BufferFull</span></a></span></span><span>
</span><span id="line-280"></span><span>      </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-281"></span><span>      </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-282"></span><span>                     </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077838"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-283"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="InsertChunk"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#InsertChunk"><span class="hs-identifier hs-var">InsertChunk</span></a></span></span><span>
</span><span id="line-284"></span><span>      </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-285"></span><span>                     </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span>
</span><span id="line-286"></span><span>                     </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077838"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-287"></span><span>
</span><span id="line-288"></span><span class="hs-comment">-- | Signal that the current 'BuildStep' is done and has computed a value.</span><span>
</span><span id="line-289"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#done"><span class="hs-pragma hs-type">done</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-290"></span><span id="local-6989586621679078137"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#done"><span class="hs-identifier hs-type">done</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>      </span><span class="hs-comment">-- ^ Next free byte in current 'BufferRange'</span><span>
</span><span id="line-291"></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679078137"><span class="hs-identifier hs-type">a</span></a></span><span>              </span><span class="hs-comment">-- ^ Computed value</span><span>
</span><span id="line-292"></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildSignal"><span class="hs-identifier hs-type">BuildSignal</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078137"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-293"></span><span id="done"><span class="annot"><span class="annottext">done :: forall a. Ptr Word8 -&gt; a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#done"><span class="hs-identifier hs-var hs-var">done</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; a -&gt; BuildSignal a
forall a. Ptr Word8 -&gt; a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#Done"><span class="hs-identifier hs-var">Done</span></a></span><span>
</span><span id="line-294"></span><span>
</span><span id="line-295"></span><span class="hs-comment">-- | Signal that the current buffer is full.</span><span>
</span><span id="line-296"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-pragma hs-type">bufferFull</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-297"></span><span id="local-6989586621679078134"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-identifier hs-type">bufferFull</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-298"></span><span>           </span><span class="hs-comment">-- ^ Minimal size of next 'BufferRange'.</span><span>
</span><span id="line-299"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-300"></span><span>           </span><span class="hs-comment">-- ^ Next free byte in current 'BufferRange'.</span><span>
</span><span id="line-301"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078134"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-302"></span><span>           </span><span class="hs-comment">-- ^ 'BuildStep' to run on the next 'BufferRange'. This 'BuildStep'</span><span>
</span><span id="line-303"></span><span>           </span><span class="hs-comment">-- may assume that it is called with a 'BufferRange' of at least the</span><span>
</span><span id="line-304"></span><span>           </span><span class="hs-comment">-- required minimal size; i.e., the caller of this 'BuildStep' must</span><span>
</span><span id="line-305"></span><span>           </span><span class="hs-comment">-- guarantee this.</span><span>
</span><span id="line-306"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildSignal"><span class="hs-identifier hs-type">BuildSignal</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078134"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-307"></span><span id="bufferFull"><span class="annot"><span class="annottext">bufferFull :: forall a. Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-identifier hs-var hs-var">bufferFull</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
forall a. Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#BufferFull"><span class="hs-identifier hs-var">BufferFull</span></a></span><span>
</span><span id="line-308"></span><span>
</span><span id="line-309"></span><span>
</span><span id="line-310"></span><span class="hs-comment">-- | Signal that a 'S.ByteString' chunk should be inserted directly.</span><span>
</span><span id="line-311"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-pragma hs-type">insertChunk</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-312"></span><span id="local-6989586621679078131"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-identifier hs-type">insertChunk</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-313"></span><span>            </span><span class="hs-comment">-- ^ Next free byte in current 'BufferRange'</span><span>
</span><span id="line-314"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span>
</span><span id="line-315"></span><span>            </span><span class="hs-comment">-- ^ Chunk to insert.</span><span>
</span><span id="line-316"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078131"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-317"></span><span>            </span><span class="hs-comment">-- ^ 'BuildStep' to run on next 'BufferRange'</span><span>
</span><span id="line-318"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildSignal"><span class="hs-identifier hs-type">BuildSignal</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078131"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-319"></span><span id="insertChunk"><span class="annot"><span class="annottext">insertChunk :: forall a. Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-identifier hs-var hs-var">insertChunk</span></a></span></span><span> </span><span id="local-6989586621679077834"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077834"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077833"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077833"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
forall a. Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#InsertChunk"><span class="hs-identifier hs-var">InsertChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077834"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077833"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-320"></span><span>
</span><span id="line-321"></span><span>
</span><span id="line-322"></span><span class="hs-comment">-- | Fill a 'BufferRange' using a 'BuildStep'.</span><span>
</span><span id="line-323"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#fillWithBuildStep"><span class="hs-pragma hs-type">fillWithBuildStep</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-324"></span><span id="local-6989586621679078128"><span id="local-6989586621679078129"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#fillWithBuildStep"><span class="hs-identifier hs-type">fillWithBuildStep</span></a></span><span>
</span><span id="line-325"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078129"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-326"></span><span>    </span><span class="hs-comment">-- ^ Build step to use for filling the 'BufferRange'.</span><span>
</span><span id="line-327"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679078129"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078128"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-328"></span><span>    </span><span class="hs-comment">-- ^ Handling the 'done' signal</span><span>
</span><span id="line-329"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078129"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078128"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-330"></span><span>    </span><span class="hs-comment">-- ^ Handling the 'bufferFull' signal</span><span>
</span><span id="line-331"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078129"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078128"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-332"></span><span>    </span><span class="hs-comment">-- ^ Handling the 'insertChunk' signal</span><span>
</span><span id="line-333"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span>
</span><span id="line-334"></span><span>    </span><span class="hs-comment">-- ^ Buffer range to fill.</span><span>
</span><span id="line-335"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078128"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-336"></span><span>    </span><span class="hs-comment">-- ^ Value computed while filling this 'BufferRange'.</span><span>
</span><span id="line-337"></span><span id="fillWithBuildStep"><span class="annot"><span class="annottext">fillWithBuildStep :: forall a b.
BuildStep a
-&gt; (Ptr Word8 -&gt; a -&gt; IO b)
-&gt; (Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO b)
-&gt; (Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO b)
-&gt; BufferRange
-&gt; IO b
</span><a href="Data.ByteString.Builder.Internal.html#fillWithBuildStep"><span class="hs-identifier hs-var hs-var">fillWithBuildStep</span></a></span></span><span> </span><span id="local-6989586621679077831"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077831"><span class="hs-identifier hs-var">step</span></a></span></span><span> </span><span id="local-6989586621679077830"><span class="annot"><span class="annottext">Ptr Word8 -&gt; a -&gt; IO b
</span><a href="#local-6989586621679077830"><span class="hs-identifier hs-var">fDone</span></a></span></span><span> </span><span id="local-6989586621679077829"><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO b
</span><a href="#local-6989586621679077829"><span class="hs-identifier hs-var">fFull</span></a></span></span><span> </span><span id="local-6989586621679077828"><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO b
</span><a href="#local-6989586621679077828"><span class="hs-identifier hs-var">fChunk</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077827"><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077827"><span class="hs-identifier hs-var">br</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-338"></span><span>    </span><span id="local-6989586621679077826"><span class="annot"><span class="annottext">BuildSignal a
</span><a href="#local-6989586621679077826"><span class="hs-identifier hs-var">signal</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077831"><span class="hs-identifier hs-var">step</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077827"><span class="hs-identifier hs-var">br</span></a></span><span>
</span><span id="line-339"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">BuildSignal a
</span><a href="#local-6989586621679077826"><span class="hs-identifier hs-var">signal</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-340"></span><span>        </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Done"><span class="hs-identifier hs-type">Done</span></a></span><span> </span><span id="local-6989586621679077825"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077825"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077824"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077824"><span class="hs-identifier hs-var">x</span></a></span></span><span>                      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; a -&gt; IO b
</span><a href="#local-6989586621679077830"><span class="hs-identifier hs-var">fDone</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077825"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077824"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-341"></span><span>        </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferFull"><span class="hs-identifier hs-type">BufferFull</span></a></span><span> </span><span id="local-6989586621679077823"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077823"><span class="hs-identifier hs-var">minSize</span></a></span></span><span> </span><span id="local-6989586621679077822"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077822"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077821"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077821"><span class="hs-identifier hs-var">nextStep</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO b
</span><a href="#local-6989586621679077829"><span class="hs-identifier hs-var">fFull</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077822"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077823"><span class="hs-identifier hs-var">minSize</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077821"><span class="hs-identifier hs-var">nextStep</span></a></span><span>
</span><span id="line-342"></span><span>        </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#InsertChunk"><span class="hs-identifier hs-type">InsertChunk</span></a></span><span> </span><span id="local-6989586621679077820"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077820"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077819"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077819"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077818"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077818"><span class="hs-identifier hs-var">nextStep</span></a></span></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO b
</span><a href="#local-6989586621679077828"><span class="hs-identifier hs-var">fChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077820"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077819"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077818"><span class="hs-identifier hs-var">nextStep</span></a></span><span>
</span><span id="line-343"></span><span>
</span><span id="line-344"></span><span>
</span><span id="line-345"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-346"></span><span class="hs-comment">-- The 'Builder' monoid</span><span>
</span><span id="line-347"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-348"></span><span>
</span><span id="line-349"></span><span class="hs-comment">-- | 'Builder's denote sequences of bytes.</span><span>
</span><span id="line-350"></span><span class="hs-comment">-- They are 'Monoid's where</span><span>
</span><span id="line-351"></span><span class="hs-comment">--   'mempty' is the zero-length sequence and</span><span>
</span><span id="line-352"></span><span class="hs-comment">--   'mappend' is concatenation, which runs in /O(1)/.</span><span>
</span><span id="line-353"></span><span class="hs-keyword">newtype</span><span> </span><span id="Builder"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-var">Builder</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Builder"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-var">Builder</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679077816"><span class="annot"><a href="#local-6989586621679077816"><span class="hs-identifier hs-type">r</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077816"><span class="hs-identifier hs-type">r</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077816"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-354"></span><span>
</span><span id="line-355"></span><span class="hs-comment">-- | Construct a 'Builder'. In contrast to 'BuildStep's, 'Builder's are</span><span>
</span><span id="line-356"></span><span class="hs-comment">-- referentially transparent.</span><span>
</span><span id="line-357"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-pragma hs-type">builder</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-358"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-type">builder</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679078125"><span class="annot"><a href="#local-6989586621679078125"><span class="hs-identifier hs-type">r</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078125"><span class="hs-identifier hs-type">r</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078125"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-359"></span><span>        </span><span class="hs-comment">-- ^ A function that fills a 'BufferRange', calls the continuation with</span><span>
</span><span id="line-360"></span><span>        </span><span class="hs-comment">-- the updated 'BufferRange' once its done, and signals its caller how</span><span>
</span><span id="line-361"></span><span>        </span><span class="hs-comment">-- to proceed using 'done', 'bufferFull', or 'insertChunk'.</span><span>
</span><span id="line-362"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-363"></span><span>        </span><span class="hs-comment">-- This function must be referentially transparent; i.e., calling it</span><span>
</span><span id="line-364"></span><span>        </span><span class="hs-comment">-- multiple times with equally sized 'BufferRange's must result in the</span><span>
</span><span id="line-365"></span><span>        </span><span class="hs-comment">-- same sequence of bytes being written. If you need mutable state,</span><span>
</span><span id="line-366"></span><span>        </span><span class="hs-comment">-- then you must allocate it anew upon each call of this function.</span><span>
</span><span id="line-367"></span><span>        </span><span class="hs-comment">-- Moroever, this function must call the continuation once its done.</span><span>
</span><span id="line-368"></span><span>        </span><span class="hs-comment">-- Otherwise, concatenation of 'Builder's does not work. Finally, this</span><span>
</span><span id="line-369"></span><span>        </span><span class="hs-comment">-- function must write to all bytes that it claims it has written.</span><span>
</span><span id="line-370"></span><span>        </span><span class="hs-comment">-- Otherwise, the resulting 'Builder' is not guaranteed to be</span><span>
</span><span id="line-371"></span><span>        </span><span class="hs-comment">-- referentially transparent and sensitive data might leak.</span><span>
</span><span id="line-372"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-373"></span><span id="builder"><span class="annot"><span class="annottext">builder :: (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var hs-var">builder</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-var">Builder</span></a></span><span>
</span><span id="line-374"></span><span>
</span><span id="line-375"></span><span class="hs-comment">-- | The final build step that returns the 'done' signal.</span><span>
</span><span id="line-376"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#finalBuildStep"><span class="hs-identifier hs-type">finalBuildStep</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-377"></span><span id="finalBuildStep"><span class="annot"><span class="annottext">finalBuildStep :: BuildStep ()
</span><a href="Data.ByteString.Builder.Internal.html#finalBuildStep"><span class="hs-identifier hs-var hs-var">finalBuildStep</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077815"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077815"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BuildSignal () -&gt; IO (BuildSignal ())
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal () -&gt; IO (BuildSignal ()))
-&gt; BuildSignal () -&gt; IO (BuildSignal ())
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; () -&gt; BuildSignal ()
forall a. Ptr Word8 -&gt; a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#Done"><span class="hs-identifier hs-var">Done</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077815"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-378"></span><span>
</span><span id="line-379"></span><span class="hs-comment">-- | Run a 'Builder' with the 'finalBuildStep'.</span><span>
</span><span id="line-380"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runBuilder"><span class="hs-pragma hs-type">runBuilder</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-381"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runBuilder"><span class="hs-identifier hs-type">runBuilder</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>      </span><span class="hs-comment">-- ^ 'Builder' to run</span><span>
</span><span id="line-382"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- ^ 'BuildStep' that writes the byte stream of this</span><span>
</span><span id="line-383"></span><span>                           </span><span class="hs-comment">-- 'Builder' and signals 'done' upon completion.</span><span>
</span><span id="line-384"></span><span id="runBuilder"><span class="annot"><span class="annottext">runBuilder :: Builder -&gt; BuildStep ()
</span><a href="Data.ByteString.Builder.Internal.html#runBuilder"><span class="hs-identifier hs-var hs-var">runBuilder</span></a></span></span><span> </span><span id="local-6989586621679077814"><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077814"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Builder -&gt; BuildStep () -&gt; BuildStep ()
forall a. Builder -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#runBuilderWith"><span class="hs-identifier hs-var">runBuilderWith</span></a></span><span> </span><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077814"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep ()
</span><a href="Data.ByteString.Builder.Internal.html#finalBuildStep"><span class="hs-identifier hs-var">finalBuildStep</span></a></span><span>
</span><span id="line-385"></span><span>
</span><span id="line-386"></span><span class="hs-comment">-- | Run a 'Builder'.</span><span>
</span><span id="line-387"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runBuilderWith"><span class="hs-pragma hs-type">runBuilderWith</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-388"></span><span id="local-6989586621679078124"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runBuilderWith"><span class="hs-identifier hs-type">runBuilderWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>      </span><span class="hs-comment">-- ^ 'Builder' to run</span><span>
</span><span id="line-389"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078124"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-comment">-- ^ Continuation 'BuildStep'</span><span>
</span><span id="line-390"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078124"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-391"></span><span id="runBuilderWith"><span class="annot"><span class="annottext">runBuilderWith :: forall a. Builder -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#runBuilderWith"><span class="hs-identifier hs-var hs-var">runBuilderWith</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span id="local-6989586621679077813"><span class="annot"><span class="annottext">forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077813"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BuildStep a -&gt; BuildStep a
forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077813"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-392"></span><span>
</span><span id="line-393"></span><span class="hs-comment">-- | The 'Builder' denoting a zero-length sequence of bytes. This function is</span><span>
</span><span id="line-394"></span><span class="hs-comment">-- only exported for use in rewriting rules. Use 'mempty' otherwise.</span><span>
</span><span id="line-395"></span><span class="hs-pragma">{-# INLINE</span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#empty"><span class="hs-pragma hs-type">empty</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-396"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#empty"><span class="hs-identifier hs-type">empty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-397"></span><span id="empty"><span class="annot"><span class="annottext">empty :: Builder
</span><a href="Data.ByteString.Builder.Internal.html#empty"><span class="hs-identifier hs-var hs-var">empty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-var">Builder</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077812"><span class="annot"><span class="annottext">BuildStep r
</span><a href="#local-6989586621679077812"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077811"><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077811"><span class="hs-identifier hs-var">range</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">BuildStep r
</span><a href="#local-6989586621679077812"><span class="hs-identifier hs-var">cont</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077811"><span class="hs-identifier hs-var">range</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-398"></span><span class="hs-comment">-- This eta expansion (hopefully) allows GHC to worker-wrapper the</span><span>
</span><span id="line-399"></span><span class="hs-comment">-- 'BufferRange' in the 'empty' base case of loops (since</span><span>
</span><span id="line-400"></span><span class="hs-comment">-- worker-wrapper requires (TODO: verify this) that all paths match</span><span>
</span><span id="line-401"></span><span class="hs-comment">-- against the wrapped argument.</span><span>
</span><span id="line-402"></span><span>
</span><span id="line-403"></span><span class="hs-comment">-- | Concatenate two 'Builder's. This function is only exported for use in rewriting</span><span>
</span><span id="line-404"></span><span class="hs-comment">-- rules. Use 'mappend' otherwise.</span><span>
</span><span id="line-405"></span><span class="hs-pragma">{-# INLINE</span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-406"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-identifier hs-type">append</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-407"></span><span id="append"><span class="annot"><span class="annottext">append :: Builder -&gt; Builder -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-identifier hs-var hs-var">append</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span id="local-6989586621679077810"><span class="annot"><span class="annottext">forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077810"><span class="hs-identifier hs-var">b1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span id="local-6989586621679077809"><span class="annot"><span class="annottext">forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077809"><span class="hs-identifier hs-var">b2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-var">Builder</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder)
-&gt; (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep r -&gt; BuildStep r
forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077810"><span class="hs-identifier hs-var">b1</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildStep r -&gt; BuildStep r)
-&gt; (BuildStep r -&gt; BuildStep r) -&gt; BuildStep r -&gt; BuildStep r
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep r -&gt; BuildStep r
forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077809"><span class="hs-identifier hs-var">b2</span></a></span><span class="hs-cpp">

#if MIN_VERSION_base(4,9,0)
</span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679077803"><span id="local-6989586621679077805"><span class="annot"><a href="../../base/src/GHC.Base.html#Semigroup"><span class="hs-identifier hs-type">Semigroup</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-411"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-412"></span><span>  </span><span id="local-6989586621679077801"><span class="annot"><span class="annottext">&lt;&gt; :: Builder -&gt; Builder -&gt; Builder
</span><a href="../../base/src/GHC.Base.html#%3C%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Builder -&gt; Builder -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-identifier hs-var">append</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-415"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monoid"><span class="hs-identifier hs-type">Monoid</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-416"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#mempty"><span class="hs-pragma hs-type">mempty</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-417"></span><span>  </span><span id="local-6989586621679077794"><span class="annot"><span class="annottext">mempty :: Builder
</span><a href="../../base/src/GHC.Base.html#mempty"><span class="hs-identifier hs-var hs-var hs-var hs-var">mempty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Builder
</span><a href="Data.ByteString.Builder.Internal.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span>
</span><span id="line-418"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-pragma hs-type">mappend</span></a></span><span> </span><span class="hs-pragma">#-}</span><span class="hs-cpp">
#if MIN_VERSION_base(4,9,0)
</span><span>  </span><span id="local-6989586621679077792"><span class="annot"><span class="annottext">mappend :: Builder -&gt; Builder -&gt; Builder
</span><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-identifier hs-var hs-var hs-var hs-var">mappend</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Builder -&gt; Builder -&gt; Builder
forall a. Semigroup a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#%3C%3E"><span class="hs-operator hs-var">(&lt;&gt;)</span></a></span><span class="hs-cpp">
#else
</span><span>  </span><span class="hs-identifier">mappend</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">append</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#mconcat"><span class="hs-pragma hs-type">mconcat</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-425"></span><span>  </span><span id="local-6989586621679077787"><span class="annot"><span class="annottext">mconcat :: [Builder] -&gt; Builder
</span><a href="../../base/src/GHC.Base.html#mconcat"><span class="hs-identifier hs-var hs-var hs-var hs-var">mconcat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Builder -&gt; Builder -&gt; Builder) -&gt; Builder -&gt; [Builder] -&gt; Builder
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">Builder -&gt; Builder -&gt; Builder
forall a. Monoid a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-identifier hs-var">mappend</span></a></span><span> </span><span class="annot"><span class="annottext">Builder
forall a. Monoid a =&gt; a
</span><a href="../../base/src/GHC.Base.html#mempty"><span class="hs-identifier hs-var">mempty</span></a></span><span>
</span><span id="line-426"></span><span>
</span><span id="line-427"></span><span class="hs-comment">-- | Flush the current buffer. This introduces a chunk boundary.</span><span>
</span><span id="line-428"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#flush"><span class="hs-pragma hs-type">flush</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-429"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#flush"><span class="hs-identifier hs-type">flush</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-430"></span><span id="flush"><span class="annot"><span class="annottext">flush :: Builder
</span><a href="Data.ByteString.Builder.Internal.html#flush"><span class="hs-identifier hs-var hs-var">flush</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var">builder</span></a></span><span> </span><span class="annot"><span class="annottext">forall r. BuildStep r -&gt; BuildStep r
forall {m :: * -&gt; *} {a}.
Monad m =&gt;
BuildStep a -&gt; BufferRange -&gt; m (BuildSignal a)
</span><a href="#local-6989586621679077785"><span class="hs-identifier hs-var">step</span></a></span><span>
</span><span id="line-431"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-432"></span><span>    </span><span id="local-6989586621679077785"><span class="annot"><span class="annottext">step :: BuildStep a -&gt; BufferRange -&gt; m (BuildSignal a)
</span><a href="#local-6989586621679077785"><span class="hs-identifier hs-var hs-var">step</span></a></span></span><span> </span><span id="local-6989586621679077781"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077781"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077780"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077780"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BuildSignal a -&gt; m (BuildSignal a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal a -&gt; m (BuildSignal a))
-&gt; BuildSignal a -&gt; m (BuildSignal a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
forall a. Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-identifier hs-var">insertChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077780"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="Data.ByteString.html#empty"><span class="hs-identifier hs-var">S.empty</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077781"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-433"></span><span>
</span><span id="line-434"></span><span>
</span><span id="line-435"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-436"></span><span class="hs-comment">-- Put</span><span>
</span><span id="line-437"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-438"></span><span>
</span><span id="line-439"></span><span class="hs-comment">-- | A 'Put' action denotes a computation of a value that writes a stream of</span><span>
</span><span id="line-440"></span><span class="hs-comment">-- bytes as a side-effect. 'Put's are strict in their side-effect; i.e., the</span><span>
</span><span id="line-441"></span><span class="hs-comment">-- stream of bytes will always be written before the computed value is</span><span>
</span><span id="line-442"></span><span class="hs-comment">-- returned.</span><span>
</span><span id="line-443"></span><span class="hs-comment">--</span><span>
</span><span id="line-444"></span><span class="hs-comment">-- 'Put's are a generalization of 'Builder's. The typical use case is the</span><span>
</span><span id="line-445"></span><span class="hs-comment">-- implementation of an encoding that might fail (e.g., an interface to the</span><span>
</span><span id="line-446"></span><span class="hs-comment">-- &lt;https://hackage.haskell.org/package/zlib zlib&gt;</span><span>
</span><span id="line-447"></span><span class="hs-comment">-- compression library or the conversion from Base64 encoded data to</span><span>
</span><span id="line-448"></span><span class="hs-comment">-- 8-bit data). For a 'Builder', the only way to handle and report such a</span><span>
</span><span id="line-449"></span><span class="hs-comment">-- failure is ignore it or call 'error'.  In contrast, 'Put' actions are</span><span>
</span><span id="line-450"></span><span class="hs-comment">-- expressive enough to allow reportng and handling such a failure in a pure</span><span>
</span><span id="line-451"></span><span class="hs-comment">-- fashion.</span><span>
</span><span id="line-452"></span><span class="hs-comment">--</span><span>
</span><span id="line-453"></span><span class="hs-comment">-- @'Put' ()@ actions are isomorphic to 'Builder's. The functions 'putBuilder'</span><span>
</span><span id="line-454"></span><span class="hs-comment">-- and 'fromPut' convert between these two types. Where possible, you should</span><span>
</span><span id="line-455"></span><span class="hs-comment">-- use 'Builder's, as sequencing them is slightly cheaper than sequencing</span><span>
</span><span id="line-456"></span><span class="hs-comment">-- 'Put's because they do not carry around a computed value.</span><span>
</span><span id="line-457"></span><span class="hs-keyword">newtype</span><span> </span><span id="Put"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span></span><span> </span><span id="local-6989586621679078108"><span class="annot"><a href="#local-6989586621679078108"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Put"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="unPut"><span class="annot"><span class="annottext">forall a. Put a -&gt; forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="Data.ByteString.Builder.Internal.html#unPut"><span class="hs-identifier hs-var hs-var">unPut</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679078107"><span class="annot"><a href="#local-6989586621679078107"><span class="hs-identifier hs-type">r</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078108"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078107"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078107"><span class="hs-identifier hs-type">r</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-458"></span><span>
</span><span id="line-459"></span><span class="hs-comment">-- | Construct a 'Put' action. In contrast to 'BuildStep's, 'Put's are</span><span>
</span><span id="line-460"></span><span class="hs-comment">-- referentially transparent in the sense that sequencing the same 'Put'</span><span>
</span><span id="line-461"></span><span class="hs-comment">-- multiple times yields every time the same value with the same side-effect.</span><span>
</span><span id="line-462"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#put"><span class="hs-pragma hs-type">put</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-463"></span><span id="local-6989586621679078104"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#put"><span class="hs-identifier hs-type">put</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679078103"><span class="annot"><a href="#local-6989586621679078103"><span class="hs-identifier hs-type">r</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078104"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078103"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078103"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-464"></span><span>       </span><span class="hs-comment">-- ^ A function that fills a 'BufferRange', calls the continuation with</span><span>
</span><span id="line-465"></span><span>       </span><span class="hs-comment">-- the updated 'BufferRange' and its computed value once its done, and</span><span>
</span><span id="line-466"></span><span>       </span><span class="hs-comment">-- signals its caller how to proceed using 'done', 'bufferFull', or</span><span>
</span><span id="line-467"></span><span>       </span><span class="hs-comment">-- 'insertChunk' signals.</span><span>
</span><span id="line-468"></span><span>       </span><span class="hs-comment">--</span><span>
</span><span id="line-469"></span><span>    </span><span class="hs-comment">-- This function must be referentially transparent; i.e., calling it</span><span>
</span><span id="line-470"></span><span>    </span><span class="hs-comment">-- multiple times with equally sized 'BufferRange's must result in the</span><span>
</span><span id="line-471"></span><span>    </span><span class="hs-comment">-- same sequence of bytes being written and the same value being</span><span>
</span><span id="line-472"></span><span>    </span><span class="hs-comment">-- computed. If you need mutable state, then you must allocate it anew</span><span>
</span><span id="line-473"></span><span>    </span><span class="hs-comment">-- upon each call of this function. Moroever, this function must call</span><span>
</span><span id="line-474"></span><span>    </span><span class="hs-comment">-- the continuation once its done. Otherwise, monadic sequencing of</span><span>
</span><span id="line-475"></span><span>    </span><span class="hs-comment">-- 'Put's does not work. Finally, this function must write to all bytes</span><span>
</span><span id="line-476"></span><span>    </span><span class="hs-comment">-- that it claims it has written. Otherwise, the resulting 'Put' is</span><span>
</span><span id="line-477"></span><span>    </span><span class="hs-comment">-- not guaranteed to be referentially transparent and sensitive data</span><span>
</span><span id="line-478"></span><span>    </span><span class="hs-comment">-- might leak.</span><span>
</span><span id="line-479"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078104"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-480"></span><span id="put"><span class="annot"><span class="annottext">put :: forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#put"><span class="hs-identifier hs-var hs-var">put</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span>
</span><span id="line-481"></span><span>
</span><span id="line-482"></span><span class="hs-comment">-- | Run a 'Put'.</span><span>
</span><span id="line-483"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runPut"><span class="hs-pragma hs-type">runPut</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-484"></span><span id="local-6989586621679078101"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#runPut"><span class="hs-identifier hs-type">runPut</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078101"><span class="hs-identifier hs-type">a</span></a></span><span>       </span><span class="hs-comment">-- ^ Put to run</span><span>
</span><span id="line-485"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078101"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-comment">-- ^ 'BuildStep' that first writes the byte stream of</span><span>
</span><span id="line-486"></span><span>                      </span><span class="hs-comment">-- this 'Put' and then yields the computed value using</span><span>
</span><span id="line-487"></span><span>                      </span><span class="hs-comment">-- the 'done' signal.</span><span>
</span><span id="line-488"></span><span id="runPut"><span class="annot"><span class="annottext">runPut :: forall a. Put a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#runPut"><span class="hs-identifier hs-var hs-var">runPut</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077775"><span class="annot"><span class="annottext">forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077775"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; BuildStep a) -&gt; BuildStep a
forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077775"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">((a -&gt; BuildStep a) -&gt; BuildStep a)
-&gt; (a -&gt; BuildStep a) -&gt; BuildStep a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077774"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077774"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077773"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077773"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">BuildSignal a -&gt; IO (BuildSignal a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal a -&gt; IO (BuildSignal a))
-&gt; BuildSignal a -&gt; IO (BuildSignal a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; a -&gt; BuildSignal a
forall a. Ptr Word8 -&gt; a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#Done"><span class="hs-identifier hs-var">Done</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077773"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077774"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-489"></span><span>
</span><span id="line-490"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679077770"><span class="annot"><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-491"></span><span>  </span><span id="local-6989586621679077768"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; Put a -&gt; Put b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span id="local-6989586621679077767"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679077767"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679077766"><span class="annot"><span class="annottext">Put a
</span><a href="#local-6989586621679077766"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b)
-&gt; (forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077765"><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077765"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Put a -&gt; forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
forall a. Put a -&gt; forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="Data.ByteString.Builder.Internal.html#unPut"><span class="hs-identifier hs-var hs-var">unPut</span></a></span><span> </span><span class="annot"><span class="annottext">Put a
</span><a href="#local-6989586621679077766"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077764"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077764"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077765"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679077767"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077764"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-492"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-pragma hs-type">fmap</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-493"></span><span>
</span><span id="line-494"></span><span class="hs-comment">-- | Synonym for '&lt;*' from 'Applicative'; used in rewriting rules.</span><span>
</span><span id="line-495"></span><span class="hs-pragma">{-# INLINE</span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-496"></span><span id="local-6989586621679078090"><span id="local-6989586621679078091"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-identifier hs-type">ap_l</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078091"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078090"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078091"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-497"></span><span id="ap_l"><span class="annot"><span class="annottext">ap_l :: forall a b. Put a -&gt; Put b -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-identifier hs-var hs-var">ap_l</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077762"><span class="annot"><span class="annottext">forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077762"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077761"><span class="annot"><span class="annottext">forall r. (b -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077761"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a)
-&gt; (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077760"><span class="annot"><span class="annottext">a -&gt; BuildStep r
</span><a href="#local-6989586621679077760"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(a -&gt; BuildStep r) -&gt; BuildStep r
forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077762"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077759"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077759"><span class="hs-identifier hs-var">a'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(b -&gt; BuildStep r) -&gt; BuildStep r
forall r. (b -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077761"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; BuildStep r
</span><a href="#local-6989586621679077760"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077759"><span class="hs-identifier hs-var">a'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-498"></span><span>
</span><span id="line-499"></span><span class="hs-comment">-- | Synonym for '*&gt;' from 'Applicative' and '&gt;&gt;' from 'Monad'; used in</span><span>
</span><span id="line-500"></span><span class="hs-comment">-- rewriting rules.</span><span>
</span><span id="line-501"></span><span class="hs-pragma">{-# INLINE</span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-502"></span><span id="local-6989586621679078085"><span id="local-6989586621679078086"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-identifier hs-type">ap_r</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078086"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078085"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078085"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-503"></span><span id="ap_r"><span class="annot"><span class="annottext">ap_r :: forall a b. Put a -&gt; Put b -&gt; Put b
</span><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-identifier hs-var hs-var">ap_r</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077757"><span class="annot"><span class="annottext">forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077757"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077756"><span class="annot"><span class="annottext">forall r. (b -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077756"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b)
-&gt; (forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077755"><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077755"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(a -&gt; BuildStep r) -&gt; BuildStep r
forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077757"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(b -&gt; BuildStep r) -&gt; BuildStep r
forall r. (b -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077756"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077755"><span class="hs-identifier hs-var">k</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-504"></span><span>
</span><span id="line-505"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679077749"><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-506"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#pure"><span class="hs-pragma hs-type">pure</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-507"></span><span>  </span><span id="local-6989586621679077745"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; Put a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621679077744"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077744"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a)
-&gt; (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077743"><span class="annot"><span class="annottext">a -&gt; BuildStep r
</span><a href="#local-6989586621679077743"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; BuildStep r
</span><a href="#local-6989586621679077743"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077744"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-508"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;*&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-509"></span><span>  </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077742"><span class="annot"><span class="annottext">forall r. ((a -&gt; b) -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077742"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679077741"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. Put (a -&gt; b) -&gt; Put a -&gt; Put b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">&lt;*&gt;</span></a></span></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077740"><span class="annot"><span class="annottext">forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077740"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b)
-&gt; (forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077739"><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077739"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">((a -&gt; b) -&gt; BuildStep r) -&gt; BuildStep r
forall r. ((a -&gt; b) -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077742"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077738"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679077738"><span class="hs-identifier hs-var">f'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(a -&gt; BuildStep r) -&gt; BuildStep r
forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077740"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077737"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077737"><span class="hs-identifier hs-var">a'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077739"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679077738"><span class="hs-identifier hs-var">f'</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077737"><span class="hs-identifier hs-var">a'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-510"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&lt;*</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-511"></span><span>  </span><span id="local-6989586621679077735"><span class="annot"><span class="annottext">&lt;* :: forall a b. Put a -&gt; Put b -&gt; Put a
</span><a href="#local-6989586621679077735"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;*)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Put a -&gt; Put b -&gt; Put a
forall a b. Put a -&gt; Put b -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-identifier hs-var">ap_l</span></a></span><span>
</span><span id="line-512"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">*&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-513"></span><span>  </span><span id="local-6989586621679077734"><span class="annot"><span class="annottext">*&gt; :: forall a b. Put a -&gt; Put b -&gt; Put b
</span><a href="../../base/src/GHC.Base.html#%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(*&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Put a -&gt; Put b -&gt; Put b
forall a b. Put a -&gt; Put b -&gt; Put b
</span><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-identifier hs-var">ap_r</span></a></span><span>
</span><span id="line-514"></span><span>
</span><span id="line-515"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-516"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#return"><span class="hs-pragma hs-type">return</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-517"></span><span>  </span><span id="local-6989586621679077725"><span class="annot"><span class="annottext">return :: forall a. a -&gt; Put a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var hs-var hs-var hs-var">return</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Put a
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span>
</span><span id="line-518"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&gt;&gt;=</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-519"></span><span>  </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077724"><span class="annot"><span class="annottext">forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077724"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679077723"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. Put a -&gt; (a -&gt; Put b) -&gt; Put b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621679077722"><span class="annot"><span class="annottext">a -&gt; Put b
</span><a href="#local-6989586621679077722"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b)
-&gt; (forall r. (b -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077721"><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077721"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(a -&gt; BuildStep r) -&gt; BuildStep r
forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077724"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077720"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077720"><span class="hs-identifier hs-var">m'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Put b -&gt; forall r. (b -&gt; BuildStep r) -&gt; BuildStep r
forall a. Put a -&gt; forall r. (a -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="Data.ByteString.Builder.Internal.html#unPut"><span class="hs-identifier hs-var hs-var">unPut</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Put b
</span><a href="#local-6989586621679077722"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077720"><span class="hs-identifier hs-var">m'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">b -&gt; BuildStep r
</span><a href="#local-6989586621679077721"><span class="hs-identifier hs-var">k</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-520"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&gt;&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-521"></span><span>  </span><span id="local-6989586621679077718"><span class="annot"><span class="annottext">&gt;&gt; :: forall a b. Put a -&gt; Put b -&gt; Put b
</span><a href="../../base/src/GHC.Base.html#%3E%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&gt;&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Put a -&gt; Put b -&gt; Put b
forall (f :: * -&gt; *) a b. Applicative f =&gt; f a -&gt; f b -&gt; f b
</span><a href="../../base/src/GHC.Base.html#%2A%3E"><span class="hs-operator hs-var">(*&gt;)</span></a></span><span>
</span><span id="line-522"></span><span>
</span><span id="line-523"></span><span class="hs-comment">-- Conversion between Put and Builder</span><span>
</span><span id="line-524"></span><span class="hs-comment">-------------------------------------</span><span>
</span><span id="line-525"></span><span>
</span><span id="line-526"></span><span class="hs-comment">-- | Run a 'Builder' as a side-effect of a @'Put' ()@ action.</span><span>
</span><span id="line-527"></span><span class="hs-pragma">{-# INLINE</span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-528"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-identifier hs-type">putBuilder</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-529"></span><span id="putBuilder"><span class="annot"><span class="annottext">putBuilder :: Builder -&gt; Put ()
</span><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-identifier hs-var hs-var">putBuilder</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span> </span><span id="local-6989586621679077717"><span class="annot"><span class="annottext">forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077717"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. (() -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put ()
forall a. (forall r. (a -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put a
</span><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-var">Put</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. (() -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put ())
-&gt; (forall r. (() -&gt; BuildStep r) -&gt; BuildStep r) -&gt; Put ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077716"><span class="annot"><span class="annottext">() -&gt; BuildStep r
</span><a href="#local-6989586621679077716"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">BuildStep r -&gt; BuildStep r
forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077717"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">() -&gt; BuildStep r
</span><a href="#local-6989586621679077716"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-530"></span><span>
</span><span id="line-531"></span><span class="hs-comment">-- | Convert a @'Put' ()@ action to a 'Builder'.</span><span>
</span><span id="line-532"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#fromPut"><span class="hs-pragma hs-type">fromPut</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-533"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#fromPut"><span class="hs-identifier hs-type">fromPut</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-534"></span><span id="fromPut"><span class="annot"><span class="annottext">fromPut :: Put () -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#fromPut"><span class="hs-identifier hs-var hs-var">fromPut</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span id="local-6989586621679077715"><span class="annot"><span class="annottext">forall r. (() -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077715"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-var">Builder</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder)
-&gt; (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077714"><span class="annot"><span class="annottext">BuildStep r
</span><a href="#local-6989586621679077714"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(() -&gt; BuildStep r) -&gt; BuildStep r
forall r. (() -&gt; BuildStep r) -&gt; BuildStep r
</span><a href="#local-6989586621679077715"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">BuildStep r
</span><a href="#local-6989586621679077714"><span class="hs-identifier hs-var">k</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-535"></span><span>
</span><span id="line-536"></span><span class="hs-comment">-- We rewrite consecutive uses of 'putBuilder' such that the append of the</span><span>
</span><span id="line-537"></span><span class="hs-comment">-- involved 'Builder's is used. This can significantly improve performance,</span><span>
</span><span id="line-538"></span><span class="hs-comment">-- when the bound-checks of the concatenated builders are fused.</span><span>
</span><span id="line-539"></span><span>
</span><span id="line-540"></span><span class="hs-comment">-- ap_l rules</span><span>
</span><span id="line-541"></span><span class="hs-pragma">{-# RULES</span><span>
</span><span id="line-542"></span><span>
</span><span id="line-543"></span><span class="annot"><span class="hs-pragma">&quot;ap_l/putBuilder&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679077713"><span class="annot"><a href="#local-6989586621679077713"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077712"><span class="annot"><a href="#local-6989586621679077712"><span class="hs-pragma hs-var">b2</span></a></span></span><span class="hs-pragma">.</span><span>
</span><span id="line-544"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077713"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077712"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-545"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077713"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077712"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-546"></span><span>
</span><span id="line-547"></span><span id="local-6989586621679077711"><span class="annot"><span class="hs-pragma">&quot;ap_l/putBuilder/assoc_r&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679077710"><span class="annot"><a href="#local-6989586621679077710"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077709"><span class="annot"><a href="#local-6989586621679077709"><span class="hs-pragma hs-var">b2</span></a></span></span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077708"><span class="annot"><a href="#local-6989586621679077708"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077711"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">.</span><span>
</span><span id="line-548"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077710"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077709"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077708"><span class="hs-pragma hs-type">p</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-549"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077710"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077709"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077708"><span class="hs-pragma hs-type">p</span></a></span></span><span>
</span><span id="line-550"></span><span>
</span><span id="line-551"></span><span id="local-6989586621679077707"><span class="annot"><span class="hs-pragma">&quot;ap_l/putBuilder/assoc_l&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077706"><span class="annot"><a href="#local-6989586621679077706"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077707"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span> </span><span id="local-6989586621679077705"><span class="annot"><a href="#local-6989586621679077705"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077704"><span class="annot"><a href="#local-6989586621679077704"><span class="hs-pragma hs-var">b2</span></a></span></span><span class="hs-pragma">.</span><span>
</span><span id="line-552"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077706"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077705"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077704"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-553"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077706"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077705"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077704"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span></span><span>
</span><span id="line-554"></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-555"></span><span>
</span><span id="line-556"></span><span class="hs-comment">-- ap_r rules</span><span>
</span><span id="line-557"></span><span class="hs-pragma">{-# RULES</span><span>
</span><span id="line-558"></span><span>
</span><span id="line-559"></span><span class="annot"><span class="hs-pragma">&quot;ap_r/putBuilder&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679077703"><span class="annot"><a href="#local-6989586621679077703"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077702"><span class="annot"><a href="#local-6989586621679077702"><span class="hs-pragma hs-var">b2</span></a></span></span><span class="hs-pragma">.</span><span>
</span><span id="line-560"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077703"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077702"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-561"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077703"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077702"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-562"></span><span>
</span><span id="line-563"></span><span id="local-6989586621679077701"><span class="annot"><span class="hs-pragma">&quot;ap_r/putBuilder/assoc_r&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679077700"><span class="annot"><a href="#local-6989586621679077700"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077699"><span class="annot"><a href="#local-6989586621679077699"><span class="hs-pragma hs-var">b2</span></a></span></span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077698"><span class="annot"><a href="#local-6989586621679077698"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077701"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">.</span><span>
</span><span id="line-564"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077700"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077699"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077698"><span class="hs-pragma hs-type">p</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-565"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077700"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077699"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077698"><span class="hs-pragma hs-type">p</span></a></span></span><span>
</span><span id="line-566"></span><span>
</span><span id="line-567"></span><span id="local-6989586621679077697"><span class="annot"><span class="hs-pragma">&quot;ap_r/putBuilder/assoc_l&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077696"><span class="annot"><a href="#local-6989586621679077696"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077697"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span> </span><span id="local-6989586621679077695"><span class="annot"><a href="#local-6989586621679077695"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077694"><span class="annot"><a href="#local-6989586621679077694"><span class="hs-pragma hs-var">b2</span></a></span></span><span class="hs-pragma">.</span><span>
</span><span id="line-568"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077696"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077695"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077694"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-569"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077696"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077695"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077694"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span></span><span>
</span><span id="line-570"></span><span>
</span><span id="line-571"></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-572"></span><span>
</span><span id="line-573"></span><span class="hs-comment">-- combined ap_l/ap_r rules</span><span>
</span><span id="line-574"></span><span class="hs-pragma">{-# RULES</span><span>
</span><span id="line-575"></span><span>
</span><span id="line-576"></span><span id="local-6989586621679077693"><span class="annot"><span class="hs-pragma">&quot;ap_l/ap_r/putBuilder/assoc_r&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679077692"><span class="annot"><a href="#local-6989586621679077692"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077691"><span class="annot"><a href="#local-6989586621679077691"><span class="hs-pragma hs-var">b2</span></a></span></span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077690"><span class="annot"><a href="#local-6989586621679077690"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077693"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">.</span><span>
</span><span id="line-577"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077692"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077691"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077690"><span class="hs-pragma hs-type">p</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-578"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077692"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077691"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077690"><span class="hs-pragma hs-type">p</span></a></span></span><span>
</span><span id="line-579"></span><span>
</span><span id="line-580"></span><span id="local-6989586621679077689"><span class="annot"><span class="hs-pragma">&quot;ap_r/ap_l/putBuilder/assoc_r&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679077688"><span class="annot"><a href="#local-6989586621679077688"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077687"><span class="annot"><a href="#local-6989586621679077687"><span class="hs-pragma hs-var">b2</span></a></span></span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077686"><span class="annot"><a href="#local-6989586621679077686"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077689"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">.</span><span>
</span><span id="line-581"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077688"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077687"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077686"><span class="hs-pragma hs-type">p</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-582"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077688"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077687"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679077686"><span class="hs-pragma hs-type">p</span></a></span></span><span>
</span><span id="line-583"></span><span>
</span><span id="line-584"></span><span id="local-6989586621679077685"><span class="annot"><span class="hs-pragma">&quot;ap_l/ap_r/putBuilder/assoc_l&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077684"><span class="annot"><a href="#local-6989586621679077684"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077685"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span> </span><span id="local-6989586621679077683"><span class="annot"><a href="#local-6989586621679077683"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077682"><span class="annot"><a href="#local-6989586621679077682"><span class="hs-pragma hs-var">b2</span></a></span></span><span class="hs-pragma">.</span><span>
</span><span id="line-585"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077684"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077683"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077682"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-586"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077684"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077683"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077682"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span></span><span>
</span><span id="line-587"></span><span>
</span><span id="line-588"></span><span id="local-6989586621679077681"><span class="annot"><span class="hs-pragma">&quot;ap_r/ap_l/putBuilder/assoc_l&quot;</span></span><span> </span><span class="hs-pragma">forall</span><span> </span><span class="hs-pragma">(</span><span id="local-6989586621679077680"><span class="annot"><a href="#local-6989586621679077680"><span class="hs-pragma hs-var">p</span></a></span></span><span> </span><span class="hs-pragma">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-pragma hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077681"><span class="hs-pragma hs-type">a</span></a></span><span class="hs-pragma">)</span><span> </span><span id="local-6989586621679077679"><span class="annot"><a href="#local-6989586621679077679"><span class="hs-pragma hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679077678"><span class="annot"><a href="#local-6989586621679077678"><span class="hs-pragma hs-var">b2</span></a></span></span><span class="hs-pragma">.</span><span>
</span><span id="line-589"></span><span>       </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_l"><span class="hs-pragma hs-type">ap_l</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077680"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077679"><span class="hs-pragma hs-type">b1</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077678"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-590"></span><span>     </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ap_r"><span class="hs-pragma hs-type">ap_r</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077680"><span class="hs-pragma hs-type">p</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putBuilder"><span class="hs-pragma hs-type">putBuilder</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#append"><span class="hs-pragma hs-type">append</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077679"><span class="hs-pragma hs-type">b1</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077678"><span class="hs-pragma hs-type">b2</span></a></span><span class="hs-pragma">)</span><span class="hs-pragma">)</span></span><span>
</span><span id="line-591"></span><span>
</span><span id="line-592"></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-593"></span><span>
</span><span id="line-594"></span><span>
</span><span id="line-595"></span><span class="hs-comment">-- Lifting IO actions</span><span>
</span><span id="line-596"></span><span class="hs-comment">---------------------</span><span>
</span><span id="line-597"></span><span>
</span><span id="line-598"></span><span class="hs-comment">{-
-- | Lift an 'IO' action to a 'Put' action.
{-# INLINE putLiftIO #-}
putLiftIO :: IO a -&gt; Put a
putLiftIO io = put $ \k br -&gt; io &gt;&gt;= (`k` br)
-}</span><span>
</span><span id="line-604"></span><span>
</span><span id="line-605"></span><span>
</span><span id="line-606"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-607"></span><span class="hs-comment">-- Executing a Put directly on a buffered Handle</span><span>
</span><span id="line-608"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-609"></span><span>
</span><span id="line-610"></span><span class="hs-comment">-- | Run a 'Put' action redirecting the produced output to a 'Handle'.</span><span>
</span><span id="line-611"></span><span class="hs-comment">--</span><span>
</span><span id="line-612"></span><span class="hs-comment">-- The output is buffered using the 'Handle's associated buffer. If this</span><span>
</span><span id="line-613"></span><span class="hs-comment">-- buffer is too small to execute one step of the 'Put' action, then</span><span>
</span><span id="line-614"></span><span class="hs-comment">-- it is replaced with a large enough buffer.</span><span>
</span><span id="line-615"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#hPut"><span class="hs-identifier hs-type">hPut</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679078048"><span class="annot"><a href="#local-6989586621679078048"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078048"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078048"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt;= 611
</span><span id="hPut"><span class="annot"><span class="annottext">hPut :: forall a. Handle -&gt; Put a -&gt; IO a
</span><a href="Data.ByteString.Builder.Internal.html#hPut"><span class="hs-identifier hs-var hs-var">hPut</span></a></span></span><span> </span><span id="local-6989586621679077673"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679077673"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679077672"><span class="annot"><span class="annottext">Put a
</span><a href="#local-6989586621679077672"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-618"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; BuildStep a -&gt; IO a
</span><a href="#local-6989586621679077671"><span class="hs-identifier hs-var">fillHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Put a -&gt; BuildStep a
forall a. Put a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#runPut"><span class="hs-identifier hs-var">runPut</span></a></span><span> </span><span class="annot"><span class="annottext">Put a
</span><a href="#local-6989586621679077672"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-619"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-620"></span><span>    </span><span class="annot"><a href="#local-6989586621679077671"><span class="hs-identifier hs-type">fillHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078048"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078048"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-621"></span><span>    </span><span id="local-6989586621679077671"><span class="annot"><span class="annottext">fillHandle :: Int -&gt; BuildStep a -&gt; IO a
</span><a href="#local-6989586621679077671"><span class="hs-identifier hs-var hs-var">fillHandle</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077670"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077670"><span class="hs-identifier hs-var">minFree</span></a></span></span><span> </span><span id="local-6989586621679077669"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077669"><span class="hs-identifier hs-var">step</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-622"></span><span>        </span><span id="local-6989586621679077668"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679077668"><span class="hs-identifier hs-var">next</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO (IO a)) -&gt; IO (IO a)
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="../../base/src/GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var">wantWritableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPut&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679077673"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (IO a)
</span><a href="#local-6989586621679077667"><span class="hs-identifier hs-var">fillHandle_</span></a></span><span>
</span><span id="line-623"></span><span>        </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679077668"><span class="hs-identifier hs-var">next</span></a></span><span>
</span><span id="line-624"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-625"></span><span>        </span><span class="hs-comment">-- | We need to return an inner IO action that is executed outside</span><span>
</span><span id="line-626"></span><span>        </span><span class="hs-comment">-- the lock taken on the Handle for two reasons:</span><span>
</span><span id="line-627"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-628"></span><span>        </span><span class="hs-comment">--   1. GHC.IO.Handle.Internals mentions in &quot;Note [async]&quot; that</span><span>
</span><span id="line-629"></span><span>        </span><span class="hs-comment">--      we should never do any side-effecting operations before</span><span>
</span><span id="line-630"></span><span>        </span><span class="hs-comment">--      an interuptible operation that may raise an async. exception</span><span>
</span><span id="line-631"></span><span>        </span><span class="hs-comment">--      as long as we are inside 'wantWritableHandle' and the like.</span><span>
</span><span id="line-632"></span><span>        </span><span class="hs-comment">--      We possibly run the interuptible 'flushWriteBuffer' right at</span><span>
</span><span id="line-633"></span><span>        </span><span class="hs-comment">--      the start of 'fillHandle', hence entering it a second time is</span><span>
</span><span id="line-634"></span><span>        </span><span class="hs-comment">--      not safe, as it could lead to a 'BuildStep' being run twice.</span><span>
</span><span id="line-635"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-636"></span><span>        </span><span class="hs-comment">--      FIXME (SM): Adapt this function or at least its documentation,</span><span>
</span><span id="line-637"></span><span>        </span><span class="hs-comment">--      as it is OK to run a 'BuildStep' twice. We dropped this</span><span>
</span><span id="line-638"></span><span>        </span><span class="hs-comment">--      requirement in favor of being able to use</span><span>
</span><span id="line-639"></span><span>        </span><span class="hs-comment">--      'unsafeDupablePerformIO' and the speed improvement that it</span><span>
</span><span id="line-640"></span><span>        </span><span class="hs-comment">--      brings.</span><span>
</span><span id="line-641"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-642"></span><span>        </span><span class="hs-comment">--   2. We use the 'S.hPut' function to also write to the handle.</span><span>
</span><span id="line-643"></span><span>        </span><span class="hs-comment">--      This function tries to take the same lock taken by</span><span>
</span><span id="line-644"></span><span>        </span><span class="hs-comment">--      'wantWritableHandle'. Therefore, we cannot call 'S.hPut'</span><span>
</span><span id="line-645"></span><span>        </span><span class="hs-comment">--      inside 'wantWritableHandle'.</span><span>
</span><span id="line-646"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-647"></span><span>        </span><span class="annot"><a href="#local-6989586621679077667"><span class="hs-identifier hs-type">fillHandle_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078048"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-648"></span><span>        </span><span id="local-6989586621679077667"><span class="annot"><span class="annottext">fillHandle_ :: Handle__ -&gt; IO (IO a)
</span><a href="#local-6989586621679077667"><span class="hs-identifier hs-var hs-var">fillHandle_</span></a></span></span><span> </span><span id="local-6989586621679077666"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679077666"><span class="hs-identifier hs-var">h_</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-649"></span><span>            </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO ()
forall {e}. Buffer e -&gt; IO ()
</span><a href="#local-6989586621679077665"><span class="hs-identifier hs-var">makeSpace</span></a></span><span>  </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; IO ()) -&gt; IO (Buffer Word8) -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; (a -&gt; m b) -&gt; m a -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3D%3C%3C"><span class="hs-operator hs-var">=&lt;&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="../../base/src/GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679077662"><span class="hs-identifier hs-var">refBuf</span></a></span><span>
</span><span id="line-650"></span><span>            </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (IO a)
</span><a href="#local-6989586621679077661"><span class="hs-identifier hs-var">fillBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; IO (IO a)) -&gt; IO (Buffer Word8) -&gt; IO (IO a)
forall (m :: * -&gt; *) a b. Monad m =&gt; (a -&gt; m b) -&gt; m a -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3D%3C%3C"><span class="hs-operator hs-var">=&lt;&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="../../base/src/GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679077662"><span class="hs-identifier hs-var">refBuf</span></a></span><span>
</span><span id="line-651"></span><span>          </span><span class="hs-keyword">where</span><span>
</span><span id="line-652"></span><span>            </span><span id="local-6989586621679077662"><span class="annot"><span class="annottext">refBuf :: IORef (Buffer Word8)
</span><a href="#local-6989586621679077662"><span class="hs-identifier hs-var hs-var">refBuf</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IORef (Buffer Word8)
</span><a href="../../base/src/GHC.IO.Handle.Types.html#haByteBuffer"><span class="hs-identifier hs-var hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679077666"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-653"></span><span>            </span><span id="local-6989586621679077659"><span class="annot"><span class="annottext">freeSpace :: Buffer e -&gt; Int
</span><a href="#local-6989586621679077659"><span class="hs-identifier hs-var hs-var">freeSpace</span></a></span></span><span> </span><span id="local-6989586621679077658"><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679077658"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer e -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="../../base/src/GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">IO.bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679077658"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer e -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="../../base/src/GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">IO.bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679077658"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-654"></span><span>
</span><span id="line-655"></span><span>            </span><span id="local-6989586621679077665"><span class="annot"><span class="annottext">makeSpace :: Buffer e -&gt; IO ()
</span><a href="#local-6989586621679077665"><span class="hs-identifier hs-var hs-var">makeSpace</span></a></span></span><span> </span><span id="local-6989586621679077648"><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679077648"><span class="hs-identifier hs-var">buf</span></a></span></span><span>
</span><span id="line-656"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer e -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="../../base/src/GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">IO.bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679077648"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077670"><span class="hs-identifier hs-var">minFree</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-657"></span><span>                  </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="../../base/src/GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-var">flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679077666"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-658"></span><span>                  </span><span id="local-6989586621679077646"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679077646"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; BufferState
forall e. Buffer e -&gt; BufferState
</span><a href="../../base/src/GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var hs-var">IO.bufState</span></a></span><span> </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; BufferState)
-&gt; IO (Buffer Word8) -&gt; IO BufferState
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="../../base/src/GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679077662"><span class="hs-identifier hs-var">refBuf</span></a></span><span>
</span><span id="line-659"></span><span>                  </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Word8)
</span><a href="../../base/src/GHC.IO.Buffer.html#newByteBuffer"><span class="hs-identifier hs-var">IO.newByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077670"><span class="hs-identifier hs-var">minFree</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679077646"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Buffer Word8) -&gt; (Buffer Word8 -&gt; IO ()) -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="../../base/src/GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679077662"><span class="hs-identifier hs-var">refBuf</span></a></span><span>
</span><span id="line-660"></span><span>
</span><span id="line-661"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer e -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="#local-6989586621679077659"><span class="hs-identifier hs-var">freeSpace</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679077648"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077670"><span class="hs-identifier hs-var">minFree</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="../../base/src/GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-var">flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679077666"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-662"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>               </span><span class="hs-glyph">=</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt;= 613
</span><span>                                          </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span>                                          </span><span class="hs-comment">-- required for ghc-6.12</span><span>
</span><span id="line-667"></span><span>                                          </span><span class="hs-identifier">flushWriteBuffer</span><span> </span><span class="hs-identifier">h_</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-670"></span><span>            </span><span id="local-6989586621679077661"><span class="annot"><span class="annottext">fillBuffer :: Buffer Word8 -&gt; IO (IO a)
</span><a href="#local-6989586621679077661"><span class="hs-identifier hs-var hs-var">fillBuffer</span></a></span></span><span> </span><span id="local-6989586621679077634"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span></span><span>
</span><span id="line-671"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="#local-6989586621679077659"><span class="hs-identifier hs-var">freeSpace</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077670"><span class="hs-identifier hs-var">minFree</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-672"></span><span>                  </span><span class="annot"><span class="annottext">String -&gt; IO (IO a)
forall a. HasCallStack =&gt; String -&gt; a
</span><a href="../../base/src/GHC.Err.html#error"><span class="hs-identifier hs-var">error</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO (IO a)) -&gt; String -&gt; IO (IO a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[String] -&gt; String
</span><a href="../../base/src/Data.OldList.html#unlines"><span class="hs-identifier hs-var">unlines</span></a></span><span>
</span><span id="line-673"></span><span>                    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Data.ByteString.Builder.Internal.hPut: internal error.&quot;</span></span><span>
</span><span id="line-674"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;  Not enough space after flush.&quot;</span></span><span>
</span><span id="line-675"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;    required: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077670"><span class="hs-identifier hs-var">minFree</span></a></span><span>
</span><span id="line-676"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;    free: &quot;</span></span><span>     </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="../../base/src/GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="#local-6989586621679077659"><span class="hs-identifier hs-var">freeSpace</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-677"></span><span>                    </span><span class="hs-special">]</span><span>
</span><span id="line-678"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-679"></span><span>                  </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077630"><span class="annot"><span class="annottext">br :: BufferRange
</span><a href="#local-6989586621679077630"><span class="hs-identifier hs-var hs-var">br</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077629"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077628"><span class="hs-identifier hs-var">pBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="../../base/src/GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">IO.bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-680"></span><span>                  </span><span id="local-6989586621679077627"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679077627"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">BuildStep a
-&gt; (Ptr Word8 -&gt; a -&gt; IO (IO a))
-&gt; (Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO (IO a))
-&gt; (Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO (IO a))
-&gt; BufferRange
-&gt; IO (IO a)
forall a b.
BuildStep a
-&gt; (Ptr Word8 -&gt; a -&gt; IO b)
-&gt; (Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO b)
-&gt; (Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO b)
-&gt; BufferRange
-&gt; IO b
</span><a href="Data.ByteString.Builder.Internal.html#fillWithBuildStep"><span class="hs-identifier hs-var">fillWithBuildStep</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077669"><span class="hs-identifier hs-var">step</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; a -&gt; IO (IO a)
forall {a} {b}. Ptr a -&gt; b -&gt; IO (IO b)
</span><a href="#local-6989586621679077626"><span class="hs-identifier hs-var">doneH</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO (IO a)
forall {a}. Ptr a -&gt; Int -&gt; BuildStep a -&gt; IO (IO a)
</span><a href="#local-6989586621679077625"><span class="hs-identifier hs-var">fullH</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO (IO a)
forall {a}. Ptr a -&gt; ByteString -&gt; BuildStep a -&gt; IO (IO a)
</span><a href="#local-6989586621679077624"><span class="hs-identifier hs-var">insertChunkH</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077630"><span class="hs-identifier hs-var">br</span></a></span><span>
</span><span id="line-681"></span><span>                  </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; IO ()
forall a. ForeignPtr a -&gt; IO ()
</span><a href="../../base/src/GHC.ForeignPtr.html#touchForeignPtr"><span class="hs-identifier hs-var">touchForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077622"><span class="hs-identifier hs-var">fpBuf</span></a></span><span>
</span><span id="line-682"></span><span>                  </span><span class="annot"><span class="annottext">IO a -&gt; IO (IO a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679077627"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-683"></span><span>              </span><span class="hs-keyword">where</span><span>
</span><span id="line-684"></span><span>                </span><span id="local-6989586621679077622"><span class="annot"><span class="annottext">fpBuf :: ForeignPtr Word8
</span><a href="#local-6989586621679077622"><span class="hs-identifier hs-var hs-var">fpBuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; ForeignPtr Word8
forall e. Buffer e -&gt; RawBuffer e
</span><a href="../../base/src/GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var hs-var">IO.bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-685"></span><span>                </span><span id="local-6989586621679077628"><span class="annot"><span class="annottext">pBuf :: Ptr Word8
</span><a href="#local-6989586621679077628"><span class="hs-identifier hs-var hs-var">pBuf</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Ptr Word8
forall a. ForeignPtr a -&gt; Ptr a
</span><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier hs-var">unsafeForeignPtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077622"><span class="hs-identifier hs-var">fpBuf</span></a></span><span>
</span><span id="line-686"></span><span>                </span><span id="local-6989586621679077629"><span class="annot"><span class="annottext">op :: Ptr b
</span><a href="#local-6989586621679077629"><span class="hs-identifier hs-var hs-var">op</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077628"><span class="hs-identifier hs-var">pBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="../../base/src/GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">IO.bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-687"></span><span>
</span><span id="line-688"></span><span>                </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621679077620"><span class="hs-pragma hs-type">updateBufR</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-689"></span><span>                </span><span id="local-6989586621679077620"><span class="annot"><span class="annottext">updateBufR :: Ptr a -&gt; IO ()
</span><a href="#local-6989586621679077620"><span class="hs-identifier hs-var hs-var">updateBufR</span></a></span></span><span> </span><span id="local-6989586621679077619"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077619"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-690"></span><span>                    </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077618"><span class="annot"><span class="annottext">off' :: Int
</span><a href="#local-6989586621679077618"><span class="hs-identifier hs-var hs-var">off'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077619"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077628"><span class="hs-identifier hs-var">pBuf</span></a></span><span>
</span><span id="line-691"></span><span>                        </span><span class="hs-glyph">!</span><span id="local-6989586621679077617"><span class="annot"><span class="annottext">buf' :: Buffer Word8
</span><a href="#local-6989586621679077617"><span class="hs-identifier hs-var hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077634"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="../../base/src/GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">IO.bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077618"><span class="hs-identifier hs-var">off'</span></a></span><span class="hs-special">}</span><span>
</span><span id="line-692"></span><span>                    </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="../../base/src/GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679077662"><span class="hs-identifier hs-var">refBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679077617"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-693"></span><span>
</span><span id="line-694"></span><span>                </span><span id="local-6989586621679077626"><span class="annot"><span class="annottext">doneH :: Ptr a -&gt; b -&gt; IO (IO b)
</span><a href="#local-6989586621679077626"><span class="hs-identifier hs-var hs-var">doneH</span></a></span></span><span> </span><span id="local-6989586621679077610"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077610"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077609"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679077609"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-695"></span><span>                    </span><span class="annot"><span class="annottext">Ptr a -&gt; IO ()
forall {a}. Ptr a -&gt; IO ()
</span><a href="#local-6989586621679077620"><span class="hs-identifier hs-var">updateBufR</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077610"><span class="hs-identifier hs-var">op'</span></a></span><span>
</span><span id="line-696"></span><span>                    </span><span class="hs-comment">-- We must flush if this Handle is set to NoBuffering.</span><span>
</span><span id="line-697"></span><span>                    </span><span class="hs-comment">-- If it is set to LineBuffering, be conservative and</span><span>
</span><span id="line-698"></span><span>                    </span><span class="hs-comment">-- flush anyway (we didn't check for newlines in the data).</span><span>
</span><span id="line-699"></span><span>                    </span><span class="hs-comment">-- Flushing must happen outside this 'wantWriteableHandle'</span><span>
</span><span id="line-700"></span><span>                    </span><span class="hs-comment">-- due to the possible async. exception.</span><span>
</span><span id="line-701"></span><span>                    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; BufferMode
</span><a href="../../base/src/GHC.IO.Handle.Types.html#haBufferMode"><span class="hs-identifier hs-var hs-var">haBufferMode</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679077666"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-702"></span><span>                        </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#BlockBuffering"><span class="hs-identifier hs-type">BlockBuffering</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; IO (IO b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(IO b -&gt; IO (IO b)) -&gt; IO b -&gt; IO (IO b)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; IO b
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679077609"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-703"></span><span>                        </span><span id="local-6989586621679077607"><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679077607"><span class="hs-identifier hs-var">_line_or_no_buffering</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; IO (IO b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(IO b -&gt; IO (IO b)) -&gt; IO b -&gt; IO (IO b)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO ()
</span><a href="../../base/src/GHC.IO.Handle.html#hFlush"><span class="hs-identifier hs-var">hFlush</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679077673"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO b -&gt; IO b
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; IO b
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679077609"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-704"></span><span>
</span><span id="line-705"></span><span>                </span><span id="local-6989586621679077625"><span class="annot"><span class="annottext">fullH :: Ptr a -&gt; Int -&gt; BuildStep a -&gt; IO (IO a)
</span><a href="#local-6989586621679077625"><span class="hs-identifier hs-var hs-var">fullH</span></a></span></span><span> </span><span id="local-6989586621679077604"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077604"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077603"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077603"><span class="hs-identifier hs-var">minSize</span></a></span></span><span> </span><span id="local-6989586621679077602"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077602"><span class="hs-identifier hs-var">nextStep</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-706"></span><span>                    </span><span class="annot"><span class="annottext">Ptr a -&gt; IO ()
forall {a}. Ptr a -&gt; IO ()
</span><a href="#local-6989586621679077620"><span class="hs-identifier hs-var">updateBufR</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077604"><span class="hs-identifier hs-var">op'</span></a></span><span>
</span><span id="line-707"></span><span>                    </span><span class="annot"><span class="annottext">IO a -&gt; IO (IO a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(IO a -&gt; IO (IO a)) -&gt; IO a -&gt; IO (IO a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; BuildStep a -&gt; IO a
</span><a href="#local-6989586621679077671"><span class="hs-identifier hs-var">fillHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077603"><span class="hs-identifier hs-var">minSize</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077602"><span class="hs-identifier hs-var">nextStep</span></a></span><span>
</span><span id="line-708"></span><span>                    </span><span class="hs-comment">-- 'fillHandle' will flush the buffer (provided there is</span><span>
</span><span id="line-709"></span><span>                    </span><span class="hs-comment">-- really less than @minSize@ space left) before executing</span><span>
</span><span id="line-710"></span><span>                    </span><span class="hs-comment">-- the 'nextStep'.</span><span>
</span><span id="line-711"></span><span>
</span><span id="line-712"></span><span>                </span><span id="local-6989586621679077624"><span class="annot"><span class="annottext">insertChunkH :: Ptr a -&gt; ByteString -&gt; BuildStep a -&gt; IO (IO a)
</span><a href="#local-6989586621679077624"><span class="hs-identifier hs-var hs-var">insertChunkH</span></a></span></span><span> </span><span id="local-6989586621679077598"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077598"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077597"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077597"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077596"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077596"><span class="hs-identifier hs-var">nextStep</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-713"></span><span>                    </span><span class="annot"><span class="annottext">Ptr a -&gt; IO ()
forall {a}. Ptr a -&gt; IO ()
</span><a href="#local-6989586621679077620"><span class="hs-identifier hs-var">updateBufR</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077598"><span class="hs-identifier hs-var">op'</span></a></span><span>
</span><span id="line-714"></span><span>                    </span><span class="annot"><span class="annottext">IO a -&gt; IO (IO a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(IO a -&gt; IO (IO a)) -&gt; IO a -&gt; IO (IO a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-715"></span><span>                        </span><span class="annot"><span class="annottext">Handle -&gt; ByteString -&gt; IO ()
</span><a href="Data.ByteString.html#hPut"><span class="hs-identifier hs-var">S.hPut</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679077673"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077597"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-716"></span><span>                        </span><span class="annot"><span class="annottext">Int -&gt; BuildStep a -&gt; IO a
</span><a href="#local-6989586621679077671"><span class="hs-identifier hs-var">fillHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077596"><span class="hs-identifier hs-var">nextStep</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-identifier">hPut</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-719"></span><span>    </span><span class="hs-identifier">go</span><span> </span><span class="hs-operator">=&lt;&lt;</span><span> </span><span class="hs-identifier">buildStepToCIOS</span><span> </span><span class="hs-identifier">strategy</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">runPut</span><span> </span><span class="hs-identifier">p</span><span class="hs-special">)</span><span>
</span><span id="line-720"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-721"></span><span>    </span><span class="hs-identifier">strategy</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">untrimmedStrategy</span><span> </span><span class="hs-identifier">L.smallChunkSize</span><span> </span><span class="hs-identifier">L.defaultChunkSize</span><span>
</span><span id="line-722"></span><span>
</span><span id="line-723"></span><span>    </span><span class="hs-identifier">go</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Finished</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">S.hPut</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">byteStringFromBuffer</span><span> </span><span class="hs-identifier">buf</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">x</span><span>
</span><span id="line-724"></span><span>    </span><span class="hs-identifier">go</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Yield1</span><span> </span><span class="hs-identifier">bs</span><span> </span><span class="hs-identifier">io</span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">S.hPut</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">bs</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">io</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">go</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-727"></span><span class="hs-comment">-- | Execute a 'Put' and return the computed result and the bytes</span><span>
</span><span id="line-728"></span><span class="hs-comment">-- written during the computation as a lazy 'L.ByteString'.</span><span>
</span><span id="line-729"></span><span class="hs-comment">--</span><span>
</span><span id="line-730"></span><span class="hs-comment">-- This function is strict in the computed result and lazy in the writing of</span><span>
</span><span id="line-731"></span><span class="hs-comment">-- the bytes. For example, given</span><span>
</span><span id="line-732"></span><span class="hs-comment">--</span><span>
</span><span id="line-733"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-734"></span><span class="hs-comment">--infinitePut = sequence_ (repeat (putBuilder (word8 1))) &gt;&gt; return 0</span><span>
</span><span id="line-735"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-736"></span><span class="hs-comment">--</span><span>
</span><span id="line-737"></span><span class="hs-comment">-- evaluating the expression</span><span>
</span><span id="line-738"></span><span class="hs-comment">--</span><span>
</span><span id="line-739"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-740"></span><span class="hs-comment">--fst $ putToLazyByteString infinitePut</span><span>
</span><span id="line-741"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-742"></span><span class="hs-comment">--</span><span>
</span><span id="line-743"></span><span class="hs-comment">-- does not terminate, while evaluating the expression</span><span>
</span><span id="line-744"></span><span class="hs-comment">--</span><span>
</span><span id="line-745"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-746"></span><span class="hs-comment">--L.head $ snd $ putToLazyByteString infinitePut</span><span>
</span><span id="line-747"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-748"></span><span class="hs-comment">--</span><span>
</span><span id="line-749"></span><span class="hs-comment">-- does terminate and yields the value @1 :: Word8@.</span><span>
</span><span id="line-750"></span><span class="hs-comment">--</span><span>
</span><span id="line-751"></span><span class="hs-comment">-- An illustrative example for these strictness properties is the</span><span>
</span><span id="line-752"></span><span class="hs-comment">-- implementation of Base64 decoding (&lt;http://en.wikipedia.org/wiki/Base64&gt;).</span><span>
</span><span id="line-753"></span><span class="hs-comment">--</span><span>
</span><span id="line-754"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-755"></span><span class="hs-comment">--type DecodingState = ...</span><span>
</span><span id="line-756"></span><span class="hs-comment">--</span><span>
</span><span id="line-757"></span><span class="hs-comment">--decodeBase64 :: 'S.ByteString' -&gt; DecodingState -&gt; 'Put' (Maybe DecodingState)</span><span>
</span><span id="line-758"></span><span class="hs-comment">--decodeBase64 = ...</span><span>
</span><span id="line-759"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-760"></span><span class="hs-comment">--</span><span>
</span><span id="line-761"></span><span class="hs-comment">-- The above function takes a strict 'S.ByteString' supposed to represent</span><span>
</span><span id="line-762"></span><span class="hs-comment">-- Base64 encoded data and the current decoding state.</span><span>
</span><span id="line-763"></span><span class="hs-comment">-- It writes the decoded bytes as the side-effect of the 'Put' and returns the</span><span>
</span><span id="line-764"></span><span class="hs-comment">-- new decoding state, if the decoding of all data in the 'S.ByteString' was</span><span>
</span><span id="line-765"></span><span class="hs-comment">-- successful. The checking if the strict 'S.ByteString' represents Base64</span><span>
</span><span id="line-766"></span><span class="hs-comment">-- encoded data and the actual decoding are fused. This makes the common case,</span><span>
</span><span id="line-767"></span><span class="hs-comment">-- where all data represents Base64 encoded data, more efficient. It also</span><span>
</span><span id="line-768"></span><span class="hs-comment">-- implies that all data must be decoded before the final decoding</span><span>
</span><span id="line-769"></span><span class="hs-comment">-- state can be returned. 'Put's are intended for implementing such fused</span><span>
</span><span id="line-770"></span><span class="hs-comment">-- checking and decoding/encoding, which is reflected in their strictness</span><span>
</span><span id="line-771"></span><span class="hs-comment">-- properties.</span><span>
</span><span id="line-772"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putToLazyByteString"><span class="hs-pragma hs-type">putToLazyByteString</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-773"></span><span id="local-6989586621679078016"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putToLazyByteString"><span class="hs-identifier hs-type">putToLazyByteString</span></a></span><span>
</span><span id="line-774"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078016"><span class="hs-identifier hs-type">a</span></a></span><span>              </span><span class="hs-comment">-- ^ 'Put' to execute</span><span>
</span><span id="line-775"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078016"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span class="hs-special">)</span></span><span>  </span><span class="hs-comment">-- ^ Result and lazy 'L.ByteString'</span><span>
</span><span id="line-776"></span><span>                          </span><span class="hs-comment">-- written as its side-effect</span><span>
</span><span id="line-777"></span><span id="putToLazyByteString"><span class="annot"><span class="annottext">putToLazyByteString :: forall a. Put a -&gt; (a, ByteString)
</span><a href="Data.ByteString.Builder.Internal.html#putToLazyByteString"><span class="hs-identifier hs-var hs-var">putToLazyByteString</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
-&gt; (a -&gt; (a, ByteString)) -&gt; Put a -&gt; (a, ByteString)
forall a b.
AllocationStrategy
-&gt; (a -&gt; (b, ByteString)) -&gt; Put a -&gt; (b, ByteString)
</span><a href="Data.ByteString.Builder.Internal.html#putToLazyByteStringWith"><span class="hs-identifier hs-var">putToLazyByteStringWith</span></a></span><span>
</span><span id="line-778"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#safeStrategy"><span class="hs-identifier hs-var">safeStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="Data.ByteString.Lazy.Internal.html#smallChunkSize"><span class="hs-identifier hs-var">L.smallChunkSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="Data.ByteString.Lazy.Internal.html#defaultChunkSize"><span class="hs-identifier hs-var">L.defaultChunkSize</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077594"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077594"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077594"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="Data.ByteString.Lazy.Internal.html#Empty"><span class="hs-identifier hs-var">L.Empty</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-779"></span><span>
</span><span id="line-780"></span><span>
</span><span id="line-781"></span><span class="hs-comment">-- | Execute a 'Put' with a buffer-allocation strategy and a continuation. For</span><span>
</span><span id="line-782"></span><span class="hs-comment">-- example, 'putToLazyByteString' is implemented as follows.</span><span>
</span><span id="line-783"></span><span class="hs-comment">--</span><span>
</span><span id="line-784"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-785"></span><span class="hs-comment">--putToLazyByteString = 'putToLazyByteStringWith'</span><span>
</span><span id="line-786"></span><span class="hs-comment">--    ('safeStrategy' 'L.smallChunkSize' 'L.defaultChunkSize') (\x -&gt; (x, L.empty))</span><span>
</span><span id="line-787"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-788"></span><span class="hs-comment">--</span><span>
</span><span id="line-789"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putToLazyByteStringWith"><span class="hs-pragma hs-type">putToLazyByteStringWith</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-790"></span><span id="local-6989586621679078013"><span id="local-6989586621679078014"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#putToLazyByteStringWith"><span class="hs-identifier hs-type">putToLazyByteStringWith</span></a></span><span>
</span><span id="line-791"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-792"></span><span>       </span><span class="hs-comment">-- ^ Buffer allocation strategy to use</span><span>
</span><span id="line-793"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078014"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078013"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-794"></span><span>       </span><span class="hs-comment">-- ^ Continuation to use for computing the final result and the tail of</span><span>
</span><span id="line-795"></span><span>       </span><span class="hs-comment">-- its side-effect (the written bytes).</span><span>
</span><span id="line-796"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Put"><span class="hs-identifier hs-type">Put</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078014"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-797"></span><span>       </span><span class="hs-comment">-- ^ 'Put' to execute</span><span>
</span><span id="line-798"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679078013"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-799"></span><span>       </span><span class="hs-comment">-- ^ Resulting lazy 'L.ByteString'</span><span>
</span><span id="line-800"></span><span id="putToLazyByteStringWith"><span class="annot"><span class="annottext">putToLazyByteStringWith :: forall a b.
AllocationStrategy
-&gt; (a -&gt; (b, ByteString)) -&gt; Put a -&gt; (b, ByteString)
</span><a href="Data.ByteString.Builder.Internal.html#putToLazyByteStringWith"><span class="hs-identifier hs-var hs-var">putToLazyByteStringWith</span></a></span></span><span> </span><span id="local-6989586621679077592"><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077592"><span class="hs-identifier hs-var">strategy</span></a></span></span><span> </span><span id="local-6989586621679077591"><span class="annot"><span class="annottext">a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077591"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span id="local-6989586621679077590"><span class="annot"><span class="annottext">Put a
</span><a href="#local-6989586621679077590"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-801"></span><span>    </span><span class="annot"><span class="annottext">AllocationStrategy
-&gt; (a -&gt; (b, ByteString)) -&gt; ChunkIOStream a -&gt; (b, ByteString)
forall a b.
AllocationStrategy
-&gt; (a -&gt; (b, ByteString)) -&gt; ChunkIOStream a -&gt; (b, ByteString)
</span><a href="Data.ByteString.Builder.Internal.html#ciosToLazyByteString"><span class="hs-identifier hs-var">ciosToLazyByteString</span></a></span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077592"><span class="hs-identifier hs-var">strategy</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; (b, ByteString)
</span><a href="#local-6989586621679077591"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; (b, ByteString))
-&gt; ChunkIOStream a -&gt; (b, ByteString)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream a) -&gt; ChunkIOStream a
forall a. IO a -&gt; a
</span><a href="../../base/src/GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier hs-var">unsafeDupablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (ChunkIOStream a) -&gt; ChunkIOStream a)
-&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-802"></span><span>        </span><span class="annot"><span class="annottext">AllocationStrategy -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
forall a. AllocationStrategy -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="Data.ByteString.Builder.Internal.html#buildStepToCIOS"><span class="hs-identifier hs-var">buildStepToCIOS</span></a></span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077592"><span class="hs-identifier hs-var">strategy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Put a -&gt; BuildStep a
forall a. Put a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#runPut"><span class="hs-identifier hs-var">runPut</span></a></span><span> </span><span class="annot"><span class="annottext">Put a
</span><a href="#local-6989586621679077590"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-803"></span><span>
</span><span id="line-804"></span><span>
</span><span id="line-805"></span><span>
</span><span id="line-806"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-807"></span><span class="hs-comment">-- ByteString insertion / controlling chunk boundaries</span><span>
</span><span id="line-808"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-809"></span><span>
</span><span id="line-810"></span><span class="hs-comment">-- Raw memory</span><span>
</span><span id="line-811"></span><span class="hs-comment">-------------</span><span>
</span><span id="line-812"></span><span>
</span><span id="line-813"></span><span class="hs-comment">-- | @'ensureFree' n@ ensures that there are at least @n@ free bytes</span><span>
</span><span id="line-814"></span><span class="hs-comment">-- for the following 'Builder'.</span><span>
</span><span id="line-815"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ensureFree"><span class="hs-pragma hs-type">ensureFree</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-816"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ensureFree"><span class="hs-identifier hs-type">ensureFree</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-817"></span><span id="ensureFree"><span class="annot"><span class="annottext">ensureFree :: Int -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#ensureFree"><span class="hs-identifier hs-var hs-var">ensureFree</span></a></span></span><span> </span><span id="local-6989586621679077589"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077589"><span class="hs-identifier hs-var">minFree</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-818"></span><span>    </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var">builder</span></a></span><span> </span><span class="annot"><span class="annottext">forall r. BuildStep r -&gt; BuildStep r
</span><a href="#local-6989586621679077588"><span class="hs-identifier hs-var">step</span></a></span><span>
</span><span id="line-819"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-820"></span><span>    </span><span id="local-6989586621679077588"><span class="annot"><span class="annottext">step :: BuildStep a -&gt; BuildStep a
</span><a href="#local-6989586621679077588"><span class="hs-identifier hs-var hs-var">step</span></a></span></span><span> </span><span id="local-6989586621679077585"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077585"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span id="local-6989586621679077584"><span class="annot"><span class="annottext">br :: BufferRange
</span><a href="#local-6989586621679077584"><span class="hs-identifier hs-var">br</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077583"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077583"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077582"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077582"><span class="hs-identifier hs-var">ope</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-821"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077582"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077583"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077589"><span class="hs-identifier hs-var">minFree</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BuildSignal a -&gt; IO (BuildSignal a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal a -&gt; IO (BuildSignal a))
-&gt; BuildSignal a -&gt; IO (BuildSignal a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
forall a. Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-identifier hs-var">bufferFull</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077589"><span class="hs-identifier hs-var">minFree</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077583"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077585"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-822"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077585"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077584"><span class="hs-identifier hs-var">br</span></a></span><span>
</span><span id="line-823"></span><span>
</span><span id="line-824"></span><span class="hs-comment">-- | Copy the bytes from a 'BufferRange' into the output stream.</span><span>
</span><span id="line-825"></span><span id="local-6989586621679078008"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#wrappedBytesCopyStep"><span class="hs-identifier hs-type">wrappedBytesCopyStep</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span>  </span><span class="hs-comment">-- ^ Input 'BufferRange'.</span><span>
</span><span id="line-826"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078008"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078008"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-827"></span><span id="wrappedBytesCopyStep"><span class="annot"><span class="annottext">wrappedBytesCopyStep :: forall a. BufferRange -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#wrappedBytesCopyStep"><span class="hs-identifier hs-var hs-var">wrappedBytesCopyStep</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077580"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077580"><span class="hs-identifier hs-var">ip0</span></a></span></span><span> </span><span id="local-6989586621679077579"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077579"><span class="hs-identifier hs-var">ipe</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679077578"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077578"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-828"></span><span>    </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; BuildStep a
</span><a href="#local-6989586621679077577"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077580"><span class="hs-identifier hs-var">ip0</span></a></span><span>
</span><span id="line-829"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-830"></span><span>    </span><span id="local-6989586621679077577"><span class="annot"><span class="annottext">go :: Ptr Word8 -&gt; BuildStep a
</span><a href="#local-6989586621679077577"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077572"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077572"><span class="hs-identifier hs-var">ip</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077571"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077571"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077570"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077570"><span class="hs-identifier hs-var">ope</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-831"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077569"><span class="hs-identifier hs-var">inpRemaining</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077567"><span class="hs-identifier hs-var">outRemaining</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-832"></span><span>          </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="../../base/src/Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier hs-var">copyBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077571"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077572"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077569"><span class="hs-identifier hs-var">inpRemaining</span></a></span><span>
</span><span id="line-833"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077565"><span class="annot"><span class="annottext">br' :: BufferRange
</span><a href="#local-6989586621679077565"><span class="hs-identifier hs-var hs-var">br'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077571"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077569"><span class="hs-identifier hs-var">inpRemaining</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077570"><span class="hs-identifier hs-var">ope</span></a></span><span>
</span><span id="line-834"></span><span>          </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077578"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077565"><span class="hs-identifier hs-var">br'</span></a></span><span>
</span><span id="line-835"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-836"></span><span>          </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="../../base/src/Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier hs-var">copyBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077571"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077572"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077567"><span class="hs-identifier hs-var">outRemaining</span></a></span><span>
</span><span id="line-837"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077564"><span class="annot"><span class="annottext">ip' :: Ptr b
</span><a href="#local-6989586621679077564"><span class="hs-identifier hs-var hs-var">ip'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077572"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077567"><span class="hs-identifier hs-var">outRemaining</span></a></span><span>
</span><span id="line-838"></span><span>          </span><span class="annot"><span class="annottext">BuildSignal a -&gt; IO (BuildSignal a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal a -&gt; IO (BuildSignal a))
-&gt; BuildSignal a -&gt; IO (BuildSignal a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
forall a. Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-identifier hs-var">bufferFull</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077570"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; BuildStep a
</span><a href="#local-6989586621679077577"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077564"><span class="hs-identifier hs-var">ip'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-839"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-840"></span><span>        </span><span id="local-6989586621679077567"><span class="annot"><span class="annottext">outRemaining :: Int
</span><a href="#local-6989586621679077567"><span class="hs-identifier hs-var hs-var">outRemaining</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077570"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077571"><span class="hs-identifier hs-var">op</span></a></span><span>
</span><span id="line-841"></span><span>        </span><span id="local-6989586621679077569"><span class="annot"><span class="annottext">inpRemaining :: Int
</span><a href="#local-6989586621679077569"><span class="hs-identifier hs-var hs-var">inpRemaining</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077579"><span class="hs-identifier hs-var">ipe</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077572"><span class="hs-identifier hs-var">ip</span></a></span><span>
</span><span id="line-842"></span><span>
</span><span id="line-843"></span><span>
</span><span id="line-844"></span><span class="hs-comment">-- Strict ByteStrings</span><span>
</span><span id="line-845"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-846"></span><span>
</span><span id="line-847"></span><span>
</span><span id="line-848"></span><span class="hs-comment">-- | Construct a 'Builder' that copies the strict 'S.ByteString's, if it is</span><span>
</span><span id="line-849"></span><span class="hs-comment">-- smaller than the treshold, and inserts it directly otherwise.</span><span>
</span><span id="line-850"></span><span class="hs-comment">--</span><span>
</span><span id="line-851"></span><span class="hs-comment">-- For example, @byteStringThreshold 1024@ copies strict 'S.ByteString's whose size</span><span>
</span><span id="line-852"></span><span class="hs-comment">-- is less or equal to 1kb, and inserts them directly otherwise. This implies</span><span>
</span><span id="line-853"></span><span class="hs-comment">-- that the average chunk-size of the generated lazy 'L.ByteString' may be as</span><span>
</span><span id="line-854"></span><span class="hs-comment">-- low as 513 bytes, as there could always be just a single byte between the</span><span>
</span><span id="line-855"></span><span class="hs-comment">-- directly inserted 1025 byte, strict 'S.ByteString's.</span><span>
</span><span id="line-856"></span><span class="hs-comment">--</span><span>
</span><span id="line-857"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringThreshold"><span class="hs-pragma hs-type">byteStringThreshold</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-858"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringThreshold"><span class="hs-identifier hs-type">byteStringThreshold</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-859"></span><span id="byteStringThreshold"><span class="annot"><span class="annottext">byteStringThreshold :: Int -&gt; ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringThreshold"><span class="hs-identifier hs-var hs-var">byteStringThreshold</span></a></span></span><span> </span><span id="local-6989586621679077563"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077563"><span class="hs-identifier hs-var">maxCopySize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-860"></span><span>    </span><span class="hs-glyph">\</span><span id="local-6989586621679077562"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077562"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var">builder</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder)
-&gt; (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; BuildStep r -&gt; BuildStep r
forall {a}. ByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="#local-6989586621679077561"><span class="hs-identifier hs-var">step</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077562"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-861"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-862"></span><span>    </span><span id="local-6989586621679077561"><span class="annot"><span class="annottext">step :: ByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="#local-6989586621679077561"><span class="hs-identifier hs-var hs-var">step</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077558"><span class="annot"><span class="annottext">bs :: ByteString
</span><a href="#local-6989586621679077558"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">S.PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679077557"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077557"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077556"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077556"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span id="local-6989586621679077555"><span class="annot"><span class="annottext">br :: BufferRange
</span><a href="#local-6989586621679077555"><span class="hs-identifier hs-var">br</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077554"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077554"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>
</span><span id="line-863"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077557"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077563"><span class="hs-identifier hs-var">maxCopySize</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; BuildStep a -&gt; BuildStep a
forall {a}. ByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#byteStringCopyStep"><span class="hs-identifier hs-var">byteStringCopyStep</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077558"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077556"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077555"><span class="hs-identifier hs-var">br</span></a></span><span>
</span><span id="line-864"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BuildSignal a -&gt; IO (BuildSignal a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal a -&gt; IO (BuildSignal a))
-&gt; BuildSignal a -&gt; IO (BuildSignal a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
forall a. Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-identifier hs-var">insertChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077554"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077558"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077556"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-865"></span><span>
</span><span id="line-866"></span><span class="hs-comment">-- | Construct a 'Builder' that copies the strict 'S.ByteString'.</span><span>
</span><span id="line-867"></span><span class="hs-comment">--</span><span>
</span><span id="line-868"></span><span class="hs-comment">-- Use this function to create 'Builder's from smallish (@&lt;= 4kb@)</span><span>
</span><span id="line-869"></span><span class="hs-comment">-- 'S.ByteString's or if you need to guarantee that the 'S.ByteString' is not</span><span>
</span><span id="line-870"></span><span class="hs-comment">-- shared with the chunks generated by the 'Builder'.</span><span>
</span><span id="line-871"></span><span class="hs-comment">--</span><span>
</span><span id="line-872"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringCopy"><span class="hs-pragma hs-type">byteStringCopy</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-873"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringCopy"><span class="hs-identifier hs-type">byteStringCopy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-874"></span><span id="byteStringCopy"><span class="annot"><span class="annottext">byteStringCopy :: ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringCopy"><span class="hs-identifier hs-var hs-var">byteStringCopy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077552"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077552"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var">builder</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder)
-&gt; (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; BuildStep r -&gt; BuildStep r
forall {a}. ByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#byteStringCopyStep"><span class="hs-identifier hs-var">byteStringCopyStep</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077552"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-875"></span><span>
</span><span id="line-876"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringCopyStep"><span class="hs-pragma hs-type">byteStringCopyStep</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-877"></span><span id="local-6989586621679077551"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringCopyStep"><span class="hs-identifier hs-type">byteStringCopyStep</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077551"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077551"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-878"></span><span id="byteStringCopyStep"><span class="annot"><span class="annottext">byteStringCopyStep :: forall {a}. ByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#byteStringCopyStep"><span class="hs-identifier hs-var hs-var">byteStringCopyStep</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-type">S.PS</span></a></span><span> </span><span id="local-6989586621679077546"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077546"><span class="hs-identifier hs-var">ifp</span></a></span></span><span> </span><span id="local-6989586621679077545"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077545"><span class="hs-identifier hs-var">ioff</span></a></span></span><span> </span><span id="local-6989586621679077544"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077544"><span class="hs-identifier hs-var">isize</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077543"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077543"><span class="hs-identifier hs-var">k0</span></a></span></span><span> </span><span id="local-6989586621679077542"><span class="annot"><span class="annottext">br0 :: BufferRange
</span><a href="#local-6989586621679077542"><span class="hs-identifier hs-var">br0</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077541"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077541"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077540"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077540"><span class="hs-identifier hs-var">ope</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-879"></span><span>    </span><span class="hs-comment">-- Ensure that the common case is not recursive and therefore yields</span><span>
</span><span id="line-880"></span><span>    </span><span class="hs-comment">-- better code.</span><span>
</span><span id="line-881"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077539"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077540"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="../../base/src/Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier hs-var">copyBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077541"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077538"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077544"><span class="hs-identifier hs-var">isize</span></a></span><span>
</span><span id="line-882"></span><span>                      </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; IO ()
forall a. ForeignPtr a -&gt; IO ()
</span><a href="../../base/src/GHC.ForeignPtr.html#touchForeignPtr"><span class="hs-identifier hs-var">touchForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077546"><span class="hs-identifier hs-var">ifp</span></a></span><span>
</span><span id="line-883"></span><span>                      </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077543"><span class="hs-identifier hs-var">k0</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077539"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077540"><span class="hs-identifier hs-var">ope</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-884"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">BufferRange -&gt; BuildStep a -&gt; BuildStep a
forall a. BufferRange -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#wrappedBytesCopyStep"><span class="hs-identifier hs-var">wrappedBytesCopyStep</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077538"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679077537"><span class="hs-identifier hs-var">ipe</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077536"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077542"><span class="hs-identifier hs-var">br0</span></a></span><span>
</span><span id="line-885"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-886"></span><span>    </span><span id="local-6989586621679077539"><span class="annot"><span class="annottext">op' :: Ptr b
</span><a href="#local-6989586621679077539"><span class="hs-identifier hs-var hs-var">op'</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077541"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077544"><span class="hs-identifier hs-var">isize</span></a></span><span>
</span><span id="line-887"></span><span>    </span><span id="local-6989586621679077538"><span class="annot"><span class="annottext">ip :: Ptr b
</span><a href="#local-6989586621679077538"><span class="hs-identifier hs-var hs-var">ip</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Ptr Word8
forall a. ForeignPtr a -&gt; Ptr a
</span><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier hs-var">unsafeForeignPtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077546"><span class="hs-identifier hs-var">ifp</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077545"><span class="hs-identifier hs-var">ioff</span></a></span><span>
</span><span id="line-888"></span><span>    </span><span id="local-6989586621679077537"><span class="annot"><span class="annottext">ipe :: Ptr b
</span><a href="#local-6989586621679077537"><span class="hs-identifier hs-var hs-var">ipe</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Any
forall {b}. Ptr b
</span><a href="#local-6989586621679077538"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077544"><span class="hs-identifier hs-var">isize</span></a></span><span>
</span><span id="line-889"></span><span>    </span><span id="local-6989586621679077536"><span class="annot"><span class="annottext">k :: BuildStep a
</span><a href="#local-6989586621679077536"><span class="hs-identifier hs-var hs-var">k</span></a></span></span><span> </span><span id="local-6989586621679077534"><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077534"><span class="hs-identifier hs-var">br</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; IO ()
forall a. ForeignPtr a -&gt; IO ()
</span><a href="../../base/src/GHC.ForeignPtr.html#touchForeignPtr"><span class="hs-identifier hs-var">touchForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077546"><span class="hs-identifier hs-var">ifp</span></a></span><span>  </span><span class="hs-comment">-- input consumed: OK to release here</span><span>
</span><span id="line-890"></span><span>              </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077543"><span class="hs-identifier hs-var">k0</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077534"><span class="hs-identifier hs-var">br</span></a></span><span>
</span><span id="line-891"></span><span>
</span><span id="line-892"></span><span class="hs-comment">-- | Construct a 'Builder' that always inserts the strict 'S.ByteString'</span><span>
</span><span id="line-893"></span><span class="hs-comment">-- directly as a chunk.</span><span>
</span><span id="line-894"></span><span class="hs-comment">--</span><span>
</span><span id="line-895"></span><span class="hs-comment">-- This implies flushing the output buffer, even if it contains just</span><span>
</span><span id="line-896"></span><span class="hs-comment">-- a single byte. You should therefore use 'byteStringInsert' only for large</span><span>
</span><span id="line-897"></span><span class="hs-comment">-- (@&gt; 8kb@) 'S.ByteString's. Otherwise, the generated chunks are too</span><span>
</span><span id="line-898"></span><span class="hs-comment">-- fragmented to be processed efficiently afterwards.</span><span>
</span><span id="line-899"></span><span class="hs-comment">--</span><span>
</span><span id="line-900"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringInsert"><span class="hs-pragma hs-type">byteStringInsert</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-901"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteStringInsert"><span class="hs-identifier hs-type">byteStringInsert</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-902"></span><span id="byteStringInsert"><span class="annot"><span class="annottext">byteStringInsert :: ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringInsert"><span class="hs-identifier hs-var hs-var">byteStringInsert</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-903"></span><span>    </span><span class="hs-glyph">\</span><span id="local-6989586621679077533"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077533"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var">builder</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder)
-&gt; (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077531"><span class="annot"><span class="annottext">BuildStep r
</span><a href="#local-6989586621679077531"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077530"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077530"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">BuildSignal r -&gt; IO (BuildSignal r)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal r -&gt; IO (BuildSignal r))
-&gt; BuildSignal r -&gt; IO (BuildSignal r)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep r -&gt; BuildSignal r
forall a. Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#insertChunk"><span class="hs-identifier hs-var">insertChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077530"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077533"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep r
</span><a href="#local-6989586621679077531"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-904"></span><span>
</span><span id="line-905"></span><span class="hs-comment">-- Short bytestrings</span><span>
</span><span id="line-906"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-907"></span><span>
</span><span id="line-908"></span><span class="hs-comment">-- | Construct a 'Builder' that copies the 'SH.ShortByteString'.</span><span>
</span><span id="line-909"></span><span class="hs-comment">--</span><span>
</span><span id="line-910"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#shortByteString"><span class="hs-pragma hs-type">shortByteString</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-911"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#shortByteString"><span class="hs-identifier hs-type">shortByteString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Short.Internal.html#ShortByteString"><span class="hs-identifier hs-type">Sh.ShortByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-912"></span><span id="shortByteString"><span class="annot"><span class="annottext">shortByteString :: ShortByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#shortByteString"><span class="hs-identifier hs-var hs-var">shortByteString</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077529"><span class="annot"><span class="annottext">ShortByteString
</span><a href="#local-6989586621679077529"><span class="hs-identifier hs-var">sbs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#builder"><span class="hs-identifier hs-var">builder</span></a></span><span> </span><span class="annot"><span class="annottext">((forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder)
-&gt; (forall r. BuildStep r -&gt; BuildStep r) -&gt; Builder
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ShortByteString -&gt; BuildStep r -&gt; BuildStep r
forall a. ShortByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#shortByteStringCopyStep"><span class="hs-identifier hs-var">shortByteStringCopyStep</span></a></span><span> </span><span class="annot"><span class="annottext">ShortByteString
</span><a href="#local-6989586621679077529"><span class="hs-identifier hs-var">sbs</span></a></span><span>
</span><span id="line-913"></span><span>
</span><span id="line-914"></span><span class="hs-comment">-- | Copy the bytes from a 'SH.ShortByteString' into the output stream.</span><span>
</span><span id="line-915"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#shortByteStringCopyStep"><span class="hs-pragma hs-type">shortByteStringCopyStep</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-916"></span><span id="local-6989586621679077993"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#shortByteStringCopyStep"><span class="hs-identifier hs-type">shortByteStringCopyStep</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Short.Internal.html#ShortByteString"><span class="hs-identifier hs-type">Sh.ShortByteString</span></a></span><span>  </span><span class="hs-comment">-- ^ Input 'SH.ShortByteString'.</span><span>
</span><span id="line-917"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077993"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679077993"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-918"></span><span id="shortByteStringCopyStep"><span class="annot"><span class="annottext">shortByteStringCopyStep :: forall a. ShortByteString -&gt; BuildStep a -&gt; BuildStep a
</span><a href="Data.ByteString.Builder.Internal.html#shortByteStringCopyStep"><span class="hs-identifier hs-var hs-var">shortByteStringCopyStep</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077527"><span class="annot"><span class="annottext">ShortByteString
</span><a href="#local-6989586621679077527"><span class="hs-identifier hs-var">sbs</span></a></span></span><span> </span><span id="local-6989586621679077526"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077526"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-919"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; BuildStep a
</span><a href="#local-6989586621679077525"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ShortByteString -&gt; Int
</span><a href="Data.ByteString.Short.Internal.html#length"><span class="hs-identifier hs-var">Sh.length</span></a></span><span> </span><span class="annot"><span class="annottext">ShortByteString
</span><a href="#local-6989586621679077527"><span class="hs-identifier hs-var">sbs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-920"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-921"></span><span>    </span><span id="local-6989586621679077525"><span class="annot"><span class="annottext">go :: Int -&gt; Int -&gt; BuildStep a
</span><a href="#local-6989586621679077525"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077519"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077519"><span class="hs-identifier hs-var">ip</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077518"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077518"><span class="hs-identifier hs-var">ipe</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span id="local-6989586621679077517"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077517"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span id="local-6989586621679077516"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077516"><span class="hs-identifier hs-var">ope</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-922"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077515"><span class="hs-identifier hs-var">inpRemaining</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077514"><span class="hs-identifier hs-var">outRemaining</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-923"></span><span>          </span><span class="annot"><span class="annottext">ShortByteString -&gt; Int -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. ShortByteString -&gt; Int -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="Data.ByteString.Short.Internal.html#copyToPtr"><span class="hs-identifier hs-var">Sh.copyToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ShortByteString
</span><a href="#local-6989586621679077527"><span class="hs-identifier hs-var">sbs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077519"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077517"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077515"><span class="hs-identifier hs-var">inpRemaining</span></a></span><span>
</span><span id="line-924"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077512"><span class="annot"><span class="annottext">br' :: BufferRange
</span><a href="#local-6989586621679077512"><span class="hs-identifier hs-var hs-var">br'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077517"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077515"><span class="hs-identifier hs-var">inpRemaining</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077516"><span class="hs-identifier hs-var">ope</span></a></span><span>
</span><span id="line-925"></span><span>          </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077526"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077512"><span class="hs-identifier hs-var">br'</span></a></span><span>
</span><span id="line-926"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-927"></span><span>          </span><span class="annot"><span class="annottext">ShortByteString -&gt; Int -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. ShortByteString -&gt; Int -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="Data.ByteString.Short.Internal.html#copyToPtr"><span class="hs-identifier hs-var">Sh.copyToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ShortByteString
</span><a href="#local-6989586621679077527"><span class="hs-identifier hs-var">sbs</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077519"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077517"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077514"><span class="hs-identifier hs-var">outRemaining</span></a></span><span>
</span><span id="line-928"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077510"><span class="annot"><span class="annottext">ip' :: Int
</span><a href="#local-6989586621679077510"><span class="hs-identifier hs-var hs-var">ip'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077519"><span class="hs-identifier hs-var">ip</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077514"><span class="hs-identifier hs-var">outRemaining</span></a></span><span>
</span><span id="line-929"></span><span>          </span><span class="annot"><span class="annottext">BuildSignal a -&gt; IO (BuildSignal a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BuildSignal a -&gt; IO (BuildSignal a))
-&gt; BuildSignal a -&gt; IO (BuildSignal a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
forall a. Int -&gt; Ptr Word8 -&gt; BuildStep a -&gt; BuildSignal a
</span><a href="Data.ByteString.Builder.Internal.html#bufferFull"><span class="hs-identifier hs-var">bufferFull</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077516"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; BuildStep a
</span><a href="#local-6989586621679077525"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077510"><span class="hs-identifier hs-var">ip'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077518"><span class="hs-identifier hs-var">ipe</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-930"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-931"></span><span>        </span><span id="local-6989586621679077514"><span class="annot"><span class="annottext">outRemaining :: Int
</span><a href="#local-6989586621679077514"><span class="hs-identifier hs-var hs-var">outRemaining</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077516"><span class="hs-identifier hs-var">ope</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077517"><span class="hs-identifier hs-var">op</span></a></span><span>
</span><span id="line-932"></span><span>        </span><span id="local-6989586621679077515"><span class="annot"><span class="annottext">inpRemaining :: Int
</span><a href="#local-6989586621679077515"><span class="hs-identifier hs-var hs-var">inpRemaining</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077518"><span class="hs-identifier hs-var">ipe</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077519"><span class="hs-identifier hs-var">ip</span></a></span><span>
</span><span id="line-933"></span><span>
</span><span id="line-934"></span><span>
</span><span id="line-935"></span><span class="hs-comment">-- Lazy bytestrings</span><span>
</span><span id="line-936"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-937"></span><span>
</span><span id="line-938"></span><span class="hs-comment">-- | Construct a 'Builder' that uses the thresholding strategy of 'byteStringThreshold'</span><span>
</span><span id="line-939"></span><span class="hs-comment">-- for each chunk of the lazy 'L.ByteString'.</span><span>
</span><span id="line-940"></span><span class="hs-comment">--</span><span>
</span><span id="line-941"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringThreshold"><span class="hs-pragma hs-type">lazyByteStringThreshold</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-942"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringThreshold"><span class="hs-identifier hs-type">lazyByteStringThreshold</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-943"></span><span id="lazyByteStringThreshold"><span class="annot"><span class="annottext">lazyByteStringThreshold :: Int -&gt; ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#lazyByteStringThreshold"><span class="hs-identifier hs-var hs-var">lazyByteStringThreshold</span></a></span></span><span> </span><span id="local-6989586621679077507"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077507"><span class="hs-identifier hs-var">maxCopySize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-944"></span><span>    </span><span class="annot"><span class="annottext">(ByteString -&gt; Builder -&gt; Builder)
-&gt; Builder -&gt; ByteString -&gt; Builder
forall a. (ByteString -&gt; a -&gt; a) -&gt; a -&gt; ByteString -&gt; a
</span><a href="Data.ByteString.Lazy.Internal.html#foldrChunks"><span class="hs-identifier hs-var">L.foldrChunks</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077505"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077505"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077504"><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077504"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringThreshold"><span class="hs-identifier hs-var">byteStringThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077507"><span class="hs-identifier hs-var">maxCopySize</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077505"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">Builder -&gt; Builder -&gt; Builder
forall a. Monoid a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-operator hs-var">`mappend`</span></a></span><span> </span><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077504"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Builder
forall a. Monoid a =&gt; a
</span><a href="../../base/src/GHC.Base.html#mempty"><span class="hs-identifier hs-var">mempty</span></a></span><span>
</span><span id="line-945"></span><span>    </span><span class="hs-comment">-- TODO: We could do better here. Currently, Large, Small, Large, leads to</span><span>
</span><span id="line-946"></span><span>    </span><span class="hs-comment">-- an unnecessary copy of the 'Small' chunk.</span><span>
</span><span id="line-947"></span><span>
</span><span id="line-948"></span><span class="hs-comment">-- | Construct a 'Builder' that copies the lazy 'L.ByteString'.</span><span>
</span><span id="line-949"></span><span class="hs-comment">--</span><span>
</span><span id="line-950"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringCopy"><span class="hs-pragma hs-type">lazyByteStringCopy</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-951"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringCopy"><span class="hs-identifier hs-type">lazyByteStringCopy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-952"></span><span id="lazyByteStringCopy"><span class="annot"><span class="annottext">lazyByteStringCopy :: ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#lazyByteStringCopy"><span class="hs-identifier hs-var hs-var">lazyByteStringCopy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-953"></span><span>    </span><span class="annot"><span class="annottext">(ByteString -&gt; Builder -&gt; Builder)
-&gt; Builder -&gt; ByteString -&gt; Builder
forall a. (ByteString -&gt; a -&gt; a) -&gt; a -&gt; ByteString -&gt; a
</span><a href="Data.ByteString.Lazy.Internal.html#foldrChunks"><span class="hs-identifier hs-var">L.foldrChunks</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077503"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077503"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077502"><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077502"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringCopy"><span class="hs-identifier hs-var">byteStringCopy</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077503"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">Builder -&gt; Builder -&gt; Builder
forall a. Monoid a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-operator hs-var">`mappend`</span></a></span><span> </span><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077502"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Builder
forall a. Monoid a =&gt; a
</span><a href="../../base/src/GHC.Base.html#mempty"><span class="hs-identifier hs-var">mempty</span></a></span><span>
</span><span id="line-954"></span><span>
</span><span id="line-955"></span><span class="hs-comment">-- | Construct a 'Builder' that inserts all chunks of the lazy 'L.ByteString'</span><span>
</span><span id="line-956"></span><span class="hs-comment">-- directly.</span><span>
</span><span id="line-957"></span><span class="hs-comment">--</span><span>
</span><span id="line-958"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringInsert"><span class="hs-pragma hs-type">lazyByteStringInsert</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-959"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteStringInsert"><span class="hs-identifier hs-type">lazyByteStringInsert</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-960"></span><span id="lazyByteStringInsert"><span class="annot"><span class="annottext">lazyByteStringInsert :: ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#lazyByteStringInsert"><span class="hs-identifier hs-var hs-var">lazyByteStringInsert</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-961"></span><span>    </span><span class="annot"><span class="annottext">(ByteString -&gt; Builder -&gt; Builder)
-&gt; Builder -&gt; ByteString -&gt; Builder
forall a. (ByteString -&gt; a -&gt; a) -&gt; a -&gt; ByteString -&gt; a
</span><a href="Data.ByteString.Lazy.Internal.html#foldrChunks"><span class="hs-identifier hs-var">L.foldrChunks</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679077501"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077501"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077500"><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077500"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringInsert"><span class="hs-identifier hs-var">byteStringInsert</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077501"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">Builder -&gt; Builder -&gt; Builder
forall a. Monoid a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-operator hs-var">`mappend`</span></a></span><span> </span><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077500"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Builder
forall a. Monoid a =&gt; a
</span><a href="../../base/src/GHC.Base.html#mempty"><span class="hs-identifier hs-var">mempty</span></a></span><span>
</span><span id="line-962"></span><span>
</span><span id="line-963"></span><span class="hs-comment">-- | Create a 'Builder' denoting the same sequence of bytes as a strict</span><span>
</span><span id="line-964"></span><span class="hs-comment">-- 'S.ByteString'.</span><span>
</span><span id="line-965"></span><span class="hs-comment">-- The 'Builder' inserts large 'S.ByteString's directly, but copies small ones</span><span>
</span><span id="line-966"></span><span class="hs-comment">-- to ensure that the generated chunks are large on average.</span><span>
</span><span id="line-967"></span><span class="hs-comment">--</span><span>
</span><span id="line-968"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteString"><span class="hs-pragma hs-type">byteString</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-969"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#byteString"><span class="hs-identifier hs-type">byteString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Internal.html#ByteString"><span class="hs-identifier hs-type">S.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-970"></span><span id="byteString"><span class="annot"><span class="annottext">byteString :: ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteString"><span class="hs-identifier hs-var hs-var">byteString</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#byteStringThreshold"><span class="hs-identifier hs-var">byteStringThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="Data.ByteString.Builder.Internal.html#maximalCopySize"><span class="hs-identifier hs-var">maximalCopySize</span></a></span><span>
</span><span id="line-971"></span><span>
</span><span id="line-972"></span><span class="hs-comment">-- | Create a 'Builder' denoting the same sequence of bytes as a lazy</span><span>
</span><span id="line-973"></span><span class="hs-comment">-- 'L.ByteString'.</span><span>
</span><span id="line-974"></span><span class="hs-comment">-- The 'Builder' inserts large chunks of the lazy 'L.ByteString' directly,</span><span>
</span><span id="line-975"></span><span class="hs-comment">-- but copies small ones to ensure that the generated chunks are large on</span><span>
</span><span id="line-976"></span><span class="hs-comment">-- average.</span><span>
</span><span id="line-977"></span><span class="hs-comment">--</span><span>
</span><span id="line-978"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteString"><span class="hs-pragma hs-type">lazyByteString</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-979"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#lazyByteString"><span class="hs-identifier hs-type">lazyByteString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-980"></span><span id="lazyByteString"><span class="annot"><span class="annottext">lazyByteString :: ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#lazyByteString"><span class="hs-identifier hs-var hs-var">lazyByteString</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ByteString -&gt; Builder
</span><a href="Data.ByteString.Builder.Internal.html#lazyByteStringThreshold"><span class="hs-identifier hs-var">lazyByteStringThreshold</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="Data.ByteString.Builder.Internal.html#maximalCopySize"><span class="hs-identifier hs-var">maximalCopySize</span></a></span><span>
</span><span id="line-981"></span><span class="hs-comment">-- FIXME: also insert the small chunk for [large,small,large] directly.</span><span>
</span><span id="line-982"></span><span class="hs-comment">-- Perhaps it makes even sense to concatenate the small chunks in</span><span>
</span><span id="line-983"></span><span class="hs-comment">-- [large,small,small,small,large] and insert them directly afterwards to avoid</span><span>
</span><span id="line-984"></span><span class="hs-comment">-- unnecessary buffer spilling. Hmm, but that uncontrollably increases latency</span><span>
</span><span id="line-985"></span><span class="hs-comment">-- =&gt; no good!</span><span>
</span><span id="line-986"></span><span>
</span><span id="line-987"></span><span class="hs-comment">-- | The maximal size of a 'S.ByteString' that is copied.</span><span>
</span><span id="line-988"></span><span class="hs-comment">-- @2 * 'L.smallChunkSize'@ to guarantee that on average a chunk is of</span><span>
</span><span id="line-989"></span><span class="hs-comment">-- 'L.smallChunkSize'.</span><span>
</span><span id="line-990"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#maximalCopySize"><span class="hs-identifier hs-type">maximalCopySize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-991"></span><span id="maximalCopySize"><span class="annot"><span class="annottext">maximalCopySize :: Int
</span><a href="Data.ByteString.Builder.Internal.html#maximalCopySize"><span class="hs-identifier hs-var hs-var">maximalCopySize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="Data.ByteString.Lazy.Internal.html#smallChunkSize"><span class="hs-identifier hs-var">L.smallChunkSize</span></a></span><span>
</span><span id="line-992"></span><span>
</span><span id="line-993"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-994"></span><span class="hs-comment">-- Builder execution</span><span>
</span><span id="line-995"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-996"></span><span>
</span><span id="line-997"></span><span class="hs-comment">-- | A buffer allocation strategy for executing 'Builder's.</span><span>
</span><span id="line-998"></span><span>
</span><span id="line-999"></span><span class="hs-comment">-- The strategy</span><span>
</span><span id="line-1000"></span><span class="hs-comment">--</span><span>
</span><span id="line-1001"></span><span class="hs-comment">-- &gt; 'AllocationStrategy' firstBufSize bufSize trim</span><span>
</span><span id="line-1002"></span><span class="hs-comment">--</span><span>
</span><span id="line-1003"></span><span class="hs-comment">-- states that the first buffer is of size @firstBufSize@, all following buffers</span><span>
</span><span id="line-1004"></span><span class="hs-comment">-- are of size @bufSize@, and a buffer of size @n@ filled with @k@ bytes should</span><span>
</span><span id="line-1005"></span><span class="hs-comment">-- be trimmed iff @trim k n@ is 'True'.</span><span>
</span><span id="line-1006"></span><span class="hs-keyword">data</span><span> </span><span id="AllocationStrategy"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-var">AllocationStrategy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="AllocationStrategy"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-var">AllocationStrategy</span></a></span></span><span>
</span><span id="line-1007"></span><span>         </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1008"></span><span>         </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-1009"></span><span>         </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1010"></span><span>
</span><span id="line-1011"></span><span class="hs-comment">-- | Create a custom allocation strategy. See the code for 'safeStrategy' and</span><span>
</span><span id="line-1012"></span><span class="hs-comment">-- 'untrimmedStrategy' for examples.</span><span>
</span><span id="line-1013"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#customStrategy"><span class="hs-pragma hs-type">customStrategy</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1014"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#customStrategy"><span class="hs-identifier hs-type">customStrategy</span></a></span><span>
</span><span id="line-1015"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1016"></span><span>     </span><span class="hs-comment">-- ^ Buffer allocation function. If 'Nothing' is given, then a new first</span><span>
</span><span id="line-1017"></span><span>     </span><span class="hs-comment">-- buffer should be allocated. If @'Just' (oldBuf, minSize)@ is given,</span><span>
</span><span id="line-1018"></span><span>     </span><span class="hs-comment">-- then a buffer with minimal size @minSize@ must be returned. The</span><span>
</span><span id="line-1019"></span><span>     </span><span class="hs-comment">-- strategy may reuse the @oldBuf@, if it can guarantee that this</span><span>
</span><span id="line-1020"></span><span>     </span><span class="hs-comment">-- referentially transparent and @oldBuf@ is large enough.</span><span>
</span><span id="line-1021"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-1022"></span><span>     </span><span class="hs-comment">-- ^ Default buffer size.</span><span>
</span><span id="line-1023"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1024"></span><span>     </span><span class="hs-comment">-- ^ A predicate @trim used allocated@ returning 'True', if the buffer</span><span>
</span><span id="line-1025"></span><span>     </span><span class="hs-comment">-- should be trimmed before it is returned.</span><span>
</span><span id="line-1026"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-1027"></span><span id="customStrategy"><span class="annot"><span class="annottext">customStrategy :: (Maybe (Buffer, Int) -&gt; IO Buffer)
-&gt; Int -&gt; (Int -&gt; Int -&gt; Bool) -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#customStrategy"><span class="hs-identifier hs-var hs-var">customStrategy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Maybe (Buffer, Int) -&gt; IO Buffer)
-&gt; Int -&gt; (Int -&gt; Int -&gt; Bool) -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-var">AllocationStrategy</span></a></span><span>
</span><span id="line-1028"></span><span>
</span><span id="line-1029"></span><span class="hs-comment">-- | Sanitize a buffer size; i.e., make it at least the size of an 'Int'.</span><span>
</span><span id="line-1030"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-pragma hs-type">sanitize</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1031"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-identifier hs-type">sanitize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-1032"></span><span id="sanitize"><span class="annot"><span class="annottext">sanitize :: Int -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-identifier hs-var hs-var">sanitize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#max"><span class="hs-identifier hs-var">max</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="../../base/src/Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
forall a. HasCallStack =&gt; a
</span><a href="../../base/src/GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1033"></span><span>
</span><span id="line-1034"></span><span class="hs-comment">-- | Use this strategy for generating lazy 'L.ByteString's whose chunks are</span><span>
</span><span id="line-1035"></span><span class="hs-comment">-- discarded right after they are generated. For example, if you just generate</span><span>
</span><span id="line-1036"></span><span class="hs-comment">-- them to write them to a network socket.</span><span>
</span><span id="line-1037"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#untrimmedStrategy"><span class="hs-pragma hs-type">untrimmedStrategy</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1038"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#untrimmedStrategy"><span class="hs-identifier hs-type">untrimmedStrategy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- ^ Size of the first buffer</span><span>
</span><span id="line-1039"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- ^ Size of successive buffers</span><span>
</span><span id="line-1040"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-1041"></span><span>                  </span><span class="hs-comment">-- ^ An allocation strategy that does not trim any of the</span><span>
</span><span id="line-1042"></span><span>                  </span><span class="hs-comment">-- filled buffers before converting it to a chunk</span><span>
</span><span id="line-1043"></span><span id="untrimmedStrategy"><span class="annot"><span class="annottext">untrimmedStrategy :: Int -&gt; Int -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#untrimmedStrategy"><span class="hs-identifier hs-var hs-var">untrimmedStrategy</span></a></span></span><span> </span><span id="local-6989586621679077494"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077494"><span class="hs-identifier hs-var">firstSize</span></a></span></span><span> </span><span id="local-6989586621679077493"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077493"><span class="hs-identifier hs-var">bufSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1044"></span><span>    </span><span class="annot"><span class="annottext">(Maybe (Buffer, Int) -&gt; IO Buffer)
-&gt; Int -&gt; (Int -&gt; Int -&gt; Bool) -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-var">AllocationStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
forall {a}. Maybe (a, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077492"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-identifier hs-var">sanitize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077493"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1045"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1046"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621679077492"><span class="hs-pragma hs-type">nextBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1047"></span><span>    </span><span id="local-6989586621679077492"><span class="annot"><span class="annottext">nextBuffer :: Maybe (a, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077492"><span class="hs-identifier hs-var hs-var">nextBuffer</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe (a, Int)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Buffer
</span><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; IO Buffer) -&gt; Int -&gt; IO Buffer
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-identifier hs-var">sanitize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077494"><span class="hs-identifier hs-var">firstSize</span></a></span><span>
</span><span id="line-1048"></span><span>    </span><span class="annot"><a href="#local-6989586621679077492"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679077491"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077491"><span class="hs-identifier hs-var">minSize</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Buffer
</span><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077491"><span class="hs-identifier hs-var">minSize</span></a></span><span>
</span><span id="line-1049"></span><span>
</span><span id="line-1050"></span><span>
</span><span id="line-1051"></span><span class="hs-comment">-- | Use this strategy for generating lazy 'L.ByteString's whose chunks are</span><span>
</span><span id="line-1052"></span><span class="hs-comment">-- likely to survive one garbage collection. This strategy trims buffers</span><span>
</span><span id="line-1053"></span><span class="hs-comment">-- that are filled less than half in order to avoid spilling too much memory.</span><span>
</span><span id="line-1054"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#safeStrategy"><span class="hs-pragma hs-type">safeStrategy</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1055"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#safeStrategy"><span class="hs-identifier hs-type">safeStrategy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>  </span><span class="hs-comment">-- ^ Size of first buffer</span><span>
</span><span id="line-1056"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>  </span><span class="hs-comment">-- ^ Size of successive buffers</span><span>
</span><span id="line-1057"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-1058"></span><span>             </span><span class="hs-comment">-- ^ An allocation strategy that guarantees that at least half</span><span>
</span><span id="line-1059"></span><span>             </span><span class="hs-comment">-- of the allocated memory is used for live data</span><span>
</span><span id="line-1060"></span><span id="safeStrategy"><span class="annot"><span class="annottext">safeStrategy :: Int -&gt; Int -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#safeStrategy"><span class="hs-identifier hs-var hs-var">safeStrategy</span></a></span></span><span> </span><span id="local-6989586621679077490"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077490"><span class="hs-identifier hs-var">firstSize</span></a></span></span><span> </span><span id="local-6989586621679077489"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077489"><span class="hs-identifier hs-var">bufSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1061"></span><span>    </span><span class="annot"><span class="annottext">(Maybe (Buffer, Int) -&gt; IO Buffer)
-&gt; Int -&gt; (Int -&gt; Int -&gt; Bool) -&gt; AllocationStrategy
</span><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-var">AllocationStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
forall {a}. Maybe (a, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077488"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-identifier hs-var">sanitize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077489"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall {a}. (Ord a, Num a) =&gt; a -&gt; a -&gt; Bool
</span><a href="#local-6989586621679077487"><span class="hs-identifier hs-var">trim</span></a></span><span>
</span><span id="line-1062"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1063"></span><span>    </span><span id="local-6989586621679077487"><span class="annot"><span class="annottext">trim :: a -&gt; a -&gt; Bool
</span><a href="#local-6989586621679077487"><span class="hs-identifier hs-var hs-var">trim</span></a></span></span><span> </span><span id="local-6989586621679077481"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077481"><span class="hs-identifier hs-var">used</span></a></span></span><span> </span><span id="local-6989586621679077480"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077480"><span class="hs-identifier hs-var">size</span></a></span></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; a
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077481"><span class="hs-identifier hs-var">used</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077480"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-1064"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621679077488"><span class="hs-pragma hs-type">nextBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1065"></span><span>    </span><span id="local-6989586621679077488"><span class="annot"><span class="annottext">nextBuffer :: Maybe (a, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077488"><span class="hs-identifier hs-var hs-var">nextBuffer</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe (a, Int)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Buffer
</span><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; IO Buffer) -&gt; Int -&gt; IO Buffer
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int
</span><a href="Data.ByteString.Builder.Internal.html#sanitize"><span class="hs-identifier hs-var">sanitize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077490"><span class="hs-identifier hs-var">firstSize</span></a></span><span>
</span><span id="line-1066"></span><span>    </span><span class="annot"><a href="#local-6989586621679077488"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679077479"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077479"><span class="hs-identifier hs-var">minSize</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Buffer
</span><a href="Data.ByteString.Builder.Internal.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077479"><span class="hs-identifier hs-var">minSize</span></a></span><span>
</span><span id="line-1067"></span><span>
</span><span id="line-1068"></span><span class="hs-comment">-- | /Heavy inlining./ Execute a 'Builder' with custom execution parameters.</span><span>
</span><span id="line-1069"></span><span class="hs-comment">--</span><span>
</span><span id="line-1070"></span><span class="hs-comment">-- This function is inlined despite its heavy code-size to allow fusing with</span><span>
</span><span id="line-1071"></span><span class="hs-comment">-- the allocation strategy. For example, the default 'Builder' execution</span><span>
</span><span id="line-1072"></span><span class="hs-comment">-- function 'Data.ByteString.Builder.toLazyByteString' is defined as follows.</span><span>
</span><span id="line-1073"></span><span class="hs-comment">--</span><span>
</span><span id="line-1074"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-1075"></span><span class="hs-comment">-- {-\# NOINLINE toLazyByteString \#-}</span><span>
</span><span id="line-1076"></span><span class="hs-comment">-- toLazyByteString =</span><span>
</span><span id="line-1077"></span><span class="hs-comment">--   toLazyByteStringWith ('safeStrategy' 'L.smallChunkSize' 'L.defaultChunkSize') L.empty</span><span>
</span><span id="line-1078"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-1079"></span><span class="hs-comment">--</span><span>
</span><span id="line-1080"></span><span class="hs-comment">-- where @L.empty@ is the zero-length lazy 'L.ByteString'.</span><span>
</span><span id="line-1081"></span><span class="hs-comment">--</span><span>
</span><span id="line-1082"></span><span class="hs-comment">-- In most cases, the parameters used by 'Data.ByteString.Builder.toLazyByteString' give good</span><span>
</span><span id="line-1083"></span><span class="hs-comment">-- performance. A sub-performing case of 'Data.ByteString.Builder.toLazyByteString' is executing short</span><span>
</span><span id="line-1084"></span><span class="hs-comment">-- (&lt;128 bytes) 'Builder's. In this case, the allocation overhead for the first</span><span>
</span><span id="line-1085"></span><span class="hs-comment">-- 4kb buffer and the trimming cost dominate the cost of executing the</span><span>
</span><span id="line-1086"></span><span class="hs-comment">-- 'Builder'. You can avoid this problem using</span><span>
</span><span id="line-1087"></span><span class="hs-comment">--</span><span>
</span><span id="line-1088"></span><span class="hs-comment">-- &gt;toLazyByteStringWith (safeStrategy 128 smallChunkSize) L.empty</span><span>
</span><span id="line-1089"></span><span class="hs-comment">--</span><span>
</span><span id="line-1090"></span><span class="hs-comment">-- This reduces the allocation and trimming overhead, as all generated</span><span>
</span><span id="line-1091"></span><span class="hs-comment">-- 'L.ByteString's fit into the first buffer and there is no trimming</span><span>
</span><span id="line-1092"></span><span class="hs-comment">-- required, if more than 64 bytes and less than 128 bytes are written.</span><span>
</span><span id="line-1093"></span><span class="hs-comment">--</span><span>
</span><span id="line-1094"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#toLazyByteStringWith"><span class="hs-pragma hs-type">toLazyByteStringWith</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1095"></span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#toLazyByteStringWith"><span class="hs-identifier hs-type">toLazyByteStringWith</span></a></span><span>
</span><span id="line-1096"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>
</span><span id="line-1097"></span><span>       </span><span class="hs-comment">-- ^ Buffer allocation strategy to use</span><span>
</span><span id="line-1098"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span>
</span><span id="line-1099"></span><span>       </span><span class="hs-comment">-- ^ Lazy 'L.ByteString' to use as the tail of the generated lazy</span><span>
</span><span id="line-1100"></span><span>       </span><span class="hs-comment">-- 'L.ByteString'</span><span>
</span><span id="line-1101"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Builder"><span class="hs-identifier hs-type">Builder</span></a></span><span>
</span><span id="line-1102"></span><span>       </span><span class="hs-comment">-- ^ 'Builder' to execute</span><span>
</span><span id="line-1103"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Lazy.Internal.html#ByteString"><span class="hs-identifier hs-type">L.ByteString</span></a></span><span>
</span><span id="line-1104"></span><span>       </span><span class="hs-comment">-- ^ Resulting lazy 'L.ByteString'</span><span>
</span><span id="line-1105"></span><span id="toLazyByteStringWith"><span class="annot"><span class="annottext">toLazyByteStringWith :: AllocationStrategy -&gt; ByteString -&gt; Builder -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#toLazyByteStringWith"><span class="hs-identifier hs-var hs-var">toLazyByteStringWith</span></a></span></span><span> </span><span id="local-6989586621679077478"><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077478"><span class="hs-identifier hs-var">strategy</span></a></span></span><span> </span><span id="local-6989586621679077477"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077477"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span id="local-6989586621679077476"><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077476"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1106"></span><span>    </span><span class="annot"><span class="annottext">AllocationStrategy -&gt; ByteString -&gt; ChunkIOStream () -&gt; ByteString
</span><a href="Data.ByteString.Builder.Internal.html#ciosUnitToLazyByteString"><span class="hs-identifier hs-var">ciosUnitToLazyByteString</span></a></span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077478"><span class="hs-identifier hs-var">strategy</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077477"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream () -&gt; ByteString) -&gt; ChunkIOStream () -&gt; ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream ()) -&gt; ChunkIOStream ()
forall a. IO a -&gt; a
</span><a href="../../base/src/GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier hs-var">unsafeDupablePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (ChunkIOStream ()) -&gt; ChunkIOStream ())
-&gt; IO (ChunkIOStream ()) -&gt; ChunkIOStream ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1107"></span><span>        </span><span class="annot"><span class="annottext">AllocationStrategy -&gt; BuildStep () -&gt; IO (ChunkIOStream ())
forall a. AllocationStrategy -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="Data.ByteString.Builder.Internal.html#buildStepToCIOS"><span class="hs-identifier hs-var">buildStepToCIOS</span></a></span><span> </span><span class="annot"><span class="annottext">AllocationStrategy
</span><a href="#local-6989586621679077478"><span class="hs-identifier hs-var">strategy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Builder -&gt; BuildStep ()
</span><a href="Data.ByteString.Builder.Internal.html#runBuilder"><span class="hs-identifier hs-var">runBuilder</span></a></span><span> </span><span class="annot"><span class="annottext">Builder
</span><a href="#local-6989586621679077476"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1108"></span><span>
</span><span id="line-1109"></span><span class="hs-comment">-- | Convert a 'BuildStep' to a 'ChunkIOStream' stream by executing it on</span><span>
</span><span id="line-1110"></span><span class="hs-comment">-- 'Buffer's allocated according to the given 'AllocationStrategy'.</span><span>
</span><span id="line-1111"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#buildStepToCIOS"><span class="hs-pragma hs-type">buildStepToCIOS</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1112"></span><span id="local-6989586621679078010"><span class="annot"><a href="Data.ByteString.Builder.Internal.html#buildStepToCIOS"><span class="hs-identifier hs-type">buildStepToCIOS</span></a></span><span>
</span><span id="line-1113"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span>          </span><span class="hs-comment">-- ^ Buffer allocation strategy to use</span><span>
</span><span id="line-1114"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BuildStep"><span class="hs-identifier hs-type">BuildStep</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078010"><span class="hs-identifier hs-type">a</span></a></span><span>                 </span><span class="hs-comment">-- ^ 'BuildStep' to execute</span><span>
</span><span id="line-1115"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#ChunkIOStream"><span class="hs-identifier hs-type">ChunkIOStream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679078010"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-1116"></span><span id="buildStepToCIOS"><span class="annot"><span class="annottext">buildStepToCIOS :: forall a. AllocationStrategy -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="Data.ByteString.Builder.Internal.html#buildStepToCIOS"><span class="hs-identifier hs-var hs-var">buildStepToCIOS</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#AllocationStrategy"><span class="hs-identifier hs-type">AllocationStrategy</span></a></span><span> </span><span id="local-6989586621679077474"><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077474"><span class="hs-identifier hs-var">nextBuffer</span></a></span></span><span> </span><span id="local-6989586621679077473"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077473"><span class="hs-identifier hs-var">bufSize</span></a></span></span><span> </span><span id="local-6989586621679077472"><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
</span><a href="#local-6989586621679077472"><span class="hs-identifier hs-var">trim</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1117"></span><span>    </span><span class="hs-glyph">\</span><span id="local-6989586621679077471"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077471"><span class="hs-identifier hs-var">step</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077474"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer, Int)
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IO Buffer
-&gt; (Buffer -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a -&gt; Buffer -&gt; IO (ChunkIOStream a)
forall {a}. BuildStep a -&gt; Buffer -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077470"><span class="hs-identifier hs-var">fill</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077471"><span class="hs-identifier hs-var">step</span></a></span><span>
</span><span id="line-1118"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1119"></span><span>    </span><span id="local-6989586621679077470"><span class="annot"><span class="annottext">fill :: BuildStep a -&gt; Buffer -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077470"><span class="hs-identifier hs-var hs-var">fill</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077465"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077465"><span class="hs-identifier hs-var">step</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077464"><span class="annot"><span class="annottext">buf :: Buffer
</span><a href="#local-6989586621679077464"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span id="local-6989586621679077463"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077463"><span class="hs-identifier hs-var">fpbuf</span></a></span></span><span> </span><span id="local-6989586621679077462"><span class="annot"><span class="annottext">br :: BufferRange
</span><a href="#local-6989586621679077462"><span class="hs-identifier hs-var">br</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-type">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679077461"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077461"><span class="hs-identifier hs-var">pe</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1120"></span><span>        </span><span id="local-6989586621679077460"><span class="annot"><span class="annottext">ChunkIOStream a
</span><a href="#local-6989586621679077460"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">BuildStep a
-&gt; (Ptr Word8 -&gt; a -&gt; IO (ChunkIOStream a))
-&gt; (Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO (ChunkIOStream a))
-&gt; (Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO (ChunkIOStream a))
-&gt; BufferRange
-&gt; IO (ChunkIOStream a)
forall a b.
BuildStep a
-&gt; (Ptr Word8 -&gt; a -&gt; IO b)
-&gt; (Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO b)
-&gt; (Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO b)
-&gt; BufferRange
-&gt; IO b
</span><a href="Data.ByteString.Builder.Internal.html#fillWithBuildStep"><span class="hs-identifier hs-var">fillWithBuildStep</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077465"><span class="hs-identifier hs-var">step</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; a -&gt; IO (ChunkIOStream a)
forall {m :: * -&gt; *} {a}.
Monad m =&gt;
Ptr Word8 -&gt; a -&gt; m (ChunkIOStream a)
</span><a href="#local-6989586621679077459"><span class="hs-identifier hs-var">doneH</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
forall {a}. Ptr a -&gt; Int -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077458"><span class="hs-identifier hs-var">fullH</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; ByteString -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
forall {a}.
Ptr a -&gt; ByteString -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077457"><span class="hs-identifier hs-var">insertChunkH</span></a></span><span> </span><span class="annot"><span class="annottext">BufferRange
</span><a href="#local-6989586621679077462"><span class="hs-identifier hs-var">br</span></a></span><span>
</span><span id="line-1121"></span><span>        </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; IO ()
forall a. ForeignPtr a -&gt; IO ()
</span><a href="../../base/src/GHC.ForeignPtr.html#touchForeignPtr"><span class="hs-identifier hs-var">touchForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077463"><span class="hs-identifier hs-var">fpbuf</span></a></span><span>
</span><span id="line-1122"></span><span>        </span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">ChunkIOStream a
</span><a href="#local-6989586621679077460"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-1123"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1124"></span><span>        </span><span id="local-6989586621679077456"><span class="annot"><span class="annottext">pbuf :: Ptr Word8
</span><a href="#local-6989586621679077456"><span class="hs-identifier hs-var hs-var">pbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Ptr Word8
forall a. ForeignPtr a -&gt; Ptr a
</span><a href="../../base/src/GHC.ForeignPtr.html#unsafeForeignPtrToPtr"><span class="hs-identifier hs-var">unsafeForeignPtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077463"><span class="hs-identifier hs-var">fpbuf</span></a></span><span>
</span><span id="line-1125"></span><span>
</span><span id="line-1126"></span><span>        </span><span id="local-6989586621679077459"><span class="annot"><span class="annottext">doneH :: Ptr Word8 -&gt; a -&gt; m (ChunkIOStream a)
</span><a href="#local-6989586621679077459"><span class="hs-identifier hs-var hs-var">doneH</span></a></span></span><span> </span><span id="local-6989586621679077453"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077453"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077452"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077452"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; m (ChunkIOStream a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; m (ChunkIOStream a))
-&gt; ChunkIOStream a -&gt; m (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1127"></span><span>            </span><span class="annot"><span class="annottext">Buffer -&gt; a -&gt; ChunkIOStream a
forall a. Buffer -&gt; a -&gt; ChunkIOStream a
</span><a href="Data.ByteString.Builder.Internal.html#Finished"><span class="hs-identifier hs-var">Finished</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; BufferRange -&gt; Buffer
</span><a href="Data.ByteString.Builder.Internal.html#Buffer"><span class="hs-identifier hs-var">Buffer</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077463"><span class="hs-identifier hs-var">fpbuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; BufferRange
</span><a href="Data.ByteString.Builder.Internal.html#BufferRange"><span class="hs-identifier hs-var">BufferRange</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077453"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077461"><span class="hs-identifier hs-var">pe</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679077452"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-1128"></span><span>
</span><span id="line-1129"></span><span>        </span><span id="local-6989586621679077458"><span class="annot"><span class="annottext">fullH :: Ptr a -&gt; Int -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077458"><span class="hs-identifier hs-var hs-var">fullH</span></a></span></span><span> </span><span id="local-6989586621679077449"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077449"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077448"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077448"><span class="hs-identifier hs-var">minSize</span></a></span></span><span> </span><span id="local-6989586621679077447"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077447"><span class="hs-identifier hs-var">nextStep</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1130"></span><span>            </span><span class="annot"><span class="annottext">Ptr a -&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
forall {a} {a}.
Ptr a -&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077446"><span class="hs-identifier hs-var">wrapChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077449"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">((Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a))
-&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO (ChunkIOStream a) -&gt; Bool -&gt; IO (ChunkIOStream a)
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (ChunkIOStream a) -&gt; Bool -&gt; IO (ChunkIOStream a))
-&gt; IO (ChunkIOStream a) -&gt; Bool -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1131"></span><span>                </span><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077474"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Buffer, Int) -&gt; Maybe (Buffer, Int)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077464"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#max"><span class="hs-identifier hs-var">max</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077448"><span class="hs-identifier hs-var">minSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077473"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO Buffer
-&gt; (Buffer -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a -&gt; Buffer -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077470"><span class="hs-identifier hs-var">fill</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077447"><span class="hs-identifier hs-var">nextStep</span></a></span><span>
</span><span id="line-1132"></span><span>
</span><span id="line-1133"></span><span>        </span><span id="local-6989586621679077457"><span class="annot"><span class="annottext">insertChunkH :: Ptr a -&gt; ByteString -&gt; BuildStep a -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077457"><span class="hs-identifier hs-var hs-var">insertChunkH</span></a></span></span><span> </span><span id="local-6989586621679077443"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077443"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077442"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077442"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span id="local-6989586621679077441"><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077441"><span class="hs-identifier hs-var">nextStep</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1134"></span><span>            </span><span class="annot"><span class="annottext">Ptr a -&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
forall {a} {a}.
Ptr a -&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077446"><span class="hs-identifier hs-var">wrapChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077443"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">((Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a))
-&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077440"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679077440"><span class="hs-identifier hs-var">isEmpty</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; IO (ChunkIOStream a) -&gt; IO (ChunkIOStream a)
forall a.
ByteString -&gt; IO (ChunkIOStream a) -&gt; IO (ChunkIOStream a)
</span><a href="Data.ByteString.Builder.Internal.html#yield1"><span class="hs-identifier hs-var">yield1</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077442"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (ChunkIOStream a) -&gt; IO (ChunkIOStream a))
-&gt; IO (ChunkIOStream a) -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1135"></span><span>                </span><span class="hs-comment">-- Checking for empty case avoids allocating 'n-1' empty</span><span>
</span><span id="line-1136"></span><span>                </span><span class="hs-comment">-- buffers for 'n' insertChunkH right after each other.</span><span>
</span><span id="line-1137"></span><span>                </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679077440"><span class="hs-identifier hs-var">isEmpty</span></a></span><span>
</span><span id="line-1138"></span><span>                  </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">BuildStep a -&gt; Buffer -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077470"><span class="hs-identifier hs-var">fill</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077441"><span class="hs-identifier hs-var">nextStep</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077464"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1139"></span><span>                  </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679077439"><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077439"><span class="hs-identifier hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer, Int) -&gt; IO Buffer
</span><a href="#local-6989586621679077474"><span class="hs-identifier hs-var">nextBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Buffer, Int) -&gt; Maybe (Buffer, Int)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077464"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077473"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1140"></span><span>                          </span><span class="annot"><span class="annottext">BuildStep a -&gt; Buffer -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077470"><span class="hs-identifier hs-var">fill</span></a></span><span> </span><span class="annot"><span class="annottext">BuildStep a
</span><a href="#local-6989586621679077441"><span class="hs-identifier hs-var">nextStep</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer
</span><a href="#local-6989586621679077439"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-1141"></span><span>
</span><span id="line-1142"></span><span>        </span><span class="hs-comment">-- Wrap and yield a chunk, trimming it if necesary</span><span>
</span><span id="line-1143"></span><span>        </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621679077446"><span class="hs-pragma hs-type">wrapChunk</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1144"></span><span>        </span><span id="local-6989586621679077446"><span class="annot"><span class="annottext">wrapChunk :: Ptr a -&gt; (Bool -&gt; IO (ChunkIOStream a)) -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077446"><span class="hs-identifier hs-var hs-var">wrapChunk</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679077432"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077432"><span class="hs-identifier hs-var">op'</span></a></span></span><span> </span><span id="local-6989586621679077431"><span class="annot"><span class="annottext">Bool -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077431"><span class="hs-identifier hs-var">mkCIOS</span></a></span></span><span>
</span><span id="line-1145"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077430"><span class="hs-identifier hs-var">chunkSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077431"><span class="hs-identifier hs-var">mkCIOS</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-1146"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
</span><a href="#local-6989586621679077472"><span class="hs-identifier hs-var">trim</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077430"><span class="hs-identifier hs-var">chunkSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077429"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1147"></span><span>              </span><span id="local-6989586621679077428"><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077428"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ByteString
</span><a href="Data.ByteString.Internal.html#create"><span class="hs-identifier hs-var">S.create</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077430"><span class="hs-identifier hs-var">chunkSize</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO ()) -&gt; IO ByteString)
-&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679077426"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077426"><span class="hs-identifier hs-var">pbuf'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1148"></span><span>                        </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="../../base/src/Foreign.Marshal.Utils.html#copyBytes"><span class="hs-identifier hs-var">copyBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077426"><span class="hs-identifier hs-var">pbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077456"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077430"><span class="hs-identifier hs-var">chunkSize</span></a></span><span>
</span><span id="line-1149"></span><span>              </span><span class="hs-comment">-- FIXME: We could reuse the trimmed buffer here.</span><span>
</span><span id="line-1150"></span><span>              </span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; IO (ChunkIOStream a))
-&gt; ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
forall a. ByteString -&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
</span><a href="Data.ByteString.Builder.Internal.html#Yield1"><span class="hs-identifier hs-var">Yield1</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679077428"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077431"><span class="hs-identifier hs-var">mkCIOS</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1151"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>            </span><span class="hs-glyph">=</span><span>
</span><span id="line-1152"></span><span>              </span><span class="annot"><span class="annottext">ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(ChunkIOStream a -&gt; IO (ChunkIOStream a))
-&gt; ChunkIOStream a -&gt; IO (ChunkIOStream a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
forall a. ByteString -&gt; IO (ChunkIOStream a) -&gt; ChunkIOStream a
</span><a href="Data.ByteString.Builder.Internal.html#Yield1"><span class="hs-identifier hs-var">Yield1</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; Int -&gt; ByteString
</span><a href="Data.ByteString.Internal.html#PS"><span class="hs-identifier hs-var">S.PS</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679077463"><span class="hs-identifier hs-var">fpbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679077430"><span class="hs-identifier hs-var">chunkSize</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; IO (ChunkIOStream a)
</span><a href="#local-6989586621679077431"><span class="hs-identifier hs-var">mkCIOS</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1153"></span><span>          </span><span class="hs-keyword">where</span><span>
</span><span id="line-1154"></span><span>            </span><span id="local-6989586621679077430"><span class="annot"><span class="annottext">chunkSize :: Int
</span><a href="#local-6989586621679077430"><span class="hs-identifier hs-var hs-var">chunkSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679077432"><span class="hs-identifier hs-var">op'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077456"><span class="hs-identifier hs-var">pbuf</span></a></span><span>
</span><span id="line-1155"></span><span>            </span><span id="local-6989586621679077429"><span class="annot"><span class="annottext">size :: Int
</span><a href="#local-6989586621679077429"><span class="hs-identifier hs-var hs-var">size</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077461"><span class="hs-identifier hs-var">pe</span></a></span><span>  </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int
forall a b. Ptr a -&gt; Ptr b -&gt; Int
</span><a href="../../base/src/GHC.Ptr.html#minusPtr"><span class="hs-operator hs-var">`minusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679077456"><span class="hs-identifier hs-var">pbuf</span></a></span><span>
</span><span id="line-1156"></span></pre></body></html>